<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span id="local-6989586621679173250"><span id="local-6989586621679173251"><span id="local-6989586621679173252"></span></span></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__
</span><span class="hs-pragma">{-# LANGUAGE RankNTypes #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE DeriveDataTypeable #-}</span><span>
</span><span id="line-5"></span><span class="hs-pragma">{-# LANGUAGE DeriveGeneric #-}</span><span>
</span><span id="line-6"></span><span class="hs-pragma">{-# LANGUAGE StandaloneDeriving #-}</span><span class="hs-cpp">
# if __GLASGOW_HASKELL__ &gt;= 710
</span><span class="hs-pragma">{-# LANGUAGE Safe #-}</span><span class="hs-cpp">
# else
</span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span class="hs-cpp">
# endif
</span><span class="hs-cpp">#endif
</span><span class="hs-cpp">
#include &quot;containers.h&quot;
</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- Module      :  Data.Graph</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2002</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-24"></span><span class="hs-comment">--</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- = Finite Graphs</span><span>
</span><span id="line-26"></span><span class="hs-comment">--</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- The @'Graph'@ type is an adjacency list representation of a finite, directed</span><span>
</span><span id="line-28"></span><span class="hs-comment">-- graph with vertices of type @Int@.</span><span>
</span><span id="line-29"></span><span class="hs-comment">--</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- The @'SCC'@ type represents a</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- &lt;https://en.wikipedia.org/wiki/Strongly_connected_component strongly-connected component&gt;</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- of a graph.</span><span>
</span><span id="line-33"></span><span class="hs-comment">--</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- == Implementation</span><span>
</span><span id="line-35"></span><span class="hs-comment">--</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- The implementation is based on</span><span>
</span><span id="line-37"></span><span class="hs-comment">--</span><span>
</span><span id="line-38"></span><span class="hs-comment">--   * /Structuring Depth-First Search Algorithms in Haskell/,</span><span>
</span><span id="line-39"></span><span class="hs-comment">--     by David King and John Launchbury, &lt;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.52.6526&gt;</span><span>
</span><span id="line-40"></span><span class="hs-comment">--</span><span>
</span><span id="line-41"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Graph</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-44"></span><span>
</span><span id="line-45"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Graphs</span></span><span>
</span><span id="line-46"></span><span>      </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier">Graph</span></a></span><span>
</span><span id="line-47"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Bounds"><span class="hs-identifier">Bounds</span></a></span><span>
</span><span id="line-48"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Edge"><span class="hs-identifier">Edge</span></a></span><span>
</span><span id="line-49"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier">Vertex</span></a></span><span>
</span><span id="line-50"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Table"><span class="hs-identifier">Table</span></a></span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Graph Construction</span></span><span>
</span><span id="line-53"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#graphFromEdges"><span class="hs-identifier">graphFromEdges</span></a></span><span>
</span><span id="line-54"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#graphFromEdges%27"><span class="hs-identifier">graphFromEdges'</span></a></span><span>
</span><span id="line-55"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#buildG"><span class="hs-identifier">buildG</span></a></span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Graph Properties</span></span><span>
</span><span id="line-58"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#vertices"><span class="hs-identifier">vertices</span></a></span><span>
</span><span id="line-59"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#edges"><span class="hs-identifier">edges</span></a></span><span>
</span><span id="line-60"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#outdegree"><span class="hs-identifier">outdegree</span></a></span><span>
</span><span id="line-61"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#indegree"><span class="hs-identifier">indegree</span></a></span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Graph Transformations</span></span><span>
</span><span id="line-64"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#transposeG"><span class="hs-identifier">transposeG</span></a></span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Graph Algorithms</span></span><span>
</span><span id="line-67"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#dfs"><span class="hs-identifier">dfs</span></a></span><span>
</span><span id="line-68"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#dff"><span class="hs-identifier">dff</span></a></span><span>
</span><span id="line-69"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#topSort"><span class="hs-identifier">topSort</span></a></span><span>
</span><span id="line-70"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#reverseTopSort"><span class="hs-identifier">reverseTopSort</span></a></span><span>
</span><span id="line-71"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#components"><span class="hs-identifier">components</span></a></span><span>
</span><span id="line-72"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#scc"><span class="hs-identifier">scc</span></a></span><span>
</span><span id="line-73"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#bcc"><span class="hs-identifier">bcc</span></a></span><span>
</span><span id="line-74"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#reachable"><span class="hs-identifier">reachable</span></a></span><span>
</span><span id="line-75"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#path"><span class="hs-identifier">path</span></a></span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span>
</span><span id="line-78"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Strongly Connected Components</span></span><span>
</span><span id="line-79"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier">SCC</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Construction</span></span><span>
</span><span id="line-82"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#stronglyConnComp"><span class="hs-identifier">stronglyConnComp</span></a></span><span>
</span><span id="line-83"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#stronglyConnCompR"><span class="hs-identifier">stronglyConnCompR</span></a></span><span>
</span><span id="line-84"></span><span>
</span><span id="line-85"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Conversion</span></span><span>
</span><span id="line-86"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#flattenSCC"><span class="hs-identifier">flattenSCC</span></a></span><span>
</span><span id="line-87"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#flattenSCCs"><span class="hs-identifier">flattenSCCs</span></a></span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Trees</span></span><span>
</span><span id="line-90"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">module</span><span> </span><span class="annot"><a href="Data.Tree.html"><span class="hs-identifier">Data.Tree</span></a></span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#if USE_ST_MONAD
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.ST.html#"><span class="hs-identifier">Control.Monad.ST</span></a></span><span>
</span><span id="line-96"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.ST.Safe.html#"><span class="hs-identifier">Data.Array.ST.Safe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../array/src/Data.Array.Base.html#newArray"><span class="hs-identifier">newArray</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Base.html#readArray"><span class="hs-identifier">readArray</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Base.html#writeArray"><span class="hs-identifier">writeArray</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
# if USE_UNBOXED_ARRAYS
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.ST.Safe.html#"><span class="hs-identifier">Data.Array.ST.Safe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../array/src/Data.Array.Base.html#STUArray"><span class="hs-identifier">STUArray</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
# else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Array.ST.Safe</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">STArray</span><span class="hs-special">)</span><span class="hs-cpp">
# endif
</span><span class="hs-cpp">#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.IntSet</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">IntSet</span><span class="hs-special">)</span><span>
</span><span id="line-104"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">Data.IntSet</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">Set</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Tree.html"><span class="hs-identifier">Data.Tree</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier">Tree</span></a></span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier">Node</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier">Forest</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span>
</span><span id="line-108"></span><span class="hs-comment">-- std interfaces</span><span>
</span><span id="line-109"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Applicative.html#"><span class="hs-identifier">Control.Applicative</span></a></span><span class="hs-cpp">
#if !MIN_VERSION_base(4,8,0)
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">Data.Foldable</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">F</span><span>
</span><span id="line-112"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Traversable</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Foldable.html#"><span class="hs-identifier">Data.Foldable</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">F</span></span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../deepseq/src/Control.DeepSeq.html#"><span class="hs-identifier">Control.DeepSeq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../deepseq/src/Control.DeepSeq.html#NFData"><span class="hs-identifier">NFData</span></a></span><span class="hs-special">(</span><span class="annot"><a href="../../deepseq/src/Control.DeepSeq.html#rnf"><span class="hs-identifier">rnf</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-117"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-118"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.html#"><span class="hs-identifier">Data.Array</span></a></span><span class="hs-cpp">
#if USE_UNBOXED_ARRAYS
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Unboxed.html#"><span class="hs-identifier">Data.Array.Unboxed</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">UA</span></span><span>
</span><span id="line-121"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Unboxed.html#"><span class="hs-identifier">Data.Array.Unboxed</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Base.html#UArray"><span class="hs-identifier">UArray</span></a></span><span> </span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">Data.Array</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">UA</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span class="hs-cpp">
#if MIN_VERSION_base(4,9,0)
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Functor.Classes.html#"><span class="hs-identifier">Data.Functor.Classes</span></a></span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">#if (!MIN_VERSION_base(4,11,0)) &amp;&amp; MIN_VERSION_base(4,9,0)
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Semigroup</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Semigroup</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">#ifdef __GLASGOW_HASKELL__
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Generics.html#"><span class="hs-identifier">GHC.Generics</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Generics.html#Generic"><span class="hs-identifier">Generic</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Generics.html#Generic1"><span class="hs-identifier">Generic1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-134"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Data.html#"><span class="hs-identifier">Data.Data</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Data.html#Data"><span class="hs-identifier">Data</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-135"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Typeable.html#"><span class="hs-identifier">Data.Typeable</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-138"></span><span class="hs-comment">-- Make sure we don't use Integer by mistake.</span><span>
</span><span id="line-139"></span><span class="hs-keyword">default</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-140"></span><span>
</span><span id="line-141"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-142"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-143"></span><span class="hs-comment">--      Strongly Connected Components</span><span>
</span><span id="line-144"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-145"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-146"></span><span>
</span><span id="line-147"></span><span class="hs-comment">-- | Strongly connected component.</span><span>
</span><span id="line-148"></span><span id="local-6989586621679173190"><span id="local-6989586621679173191"><span id="local-6989586621679173192"><span id="local-6989586621679173193"></span></span></span></span><span class="hs-keyword">data</span><span> </span><span id="SCC"><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-var">SCC</span></a></span></span><span> </span><span id="local-6989586621679173611"><span class="annot"><a href="#local-6989586621679173611"><span class="hs-identifier hs-type">vertex</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="AcyclicSCC"><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-var">AcyclicSCC</span></a></span></span><span> </span><span class="annot"><a href="#local-6989586621679173611"><span class="hs-identifier hs-type">vertex</span></a></span><span>     </span><span class="hs-comment">-- ^ A single vertex that is not</span><span>
</span><span id="line-149"></span><span>                                        </span><span class="hs-comment">-- in any cycle.</span><span>
</span><span id="line-150"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span id="CyclicSCC"><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span></span><span>  </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173611"><span class="hs-identifier hs-type">vertex</span></a></span><span class="hs-special">]</span><span>   </span><span class="hs-comment">-- ^ A maximal set of mutually</span><span>
</span><span id="line-151"></span><span>                                        </span><span class="hs-comment">-- reachable vertices.</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &gt;= 802
</span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span> </span><span id="local-6989586621679173181"><span id="local-6989586621679173186"><span class="annot"><span class="annottext">SCC vertex -&gt; SCC vertex -&gt; Bool
(SCC vertex -&gt; SCC vertex -&gt; Bool)
-&gt; (SCC vertex -&gt; SCC vertex -&gt; Bool) -&gt; Eq (SCC vertex)
forall vertex. Eq vertex =&gt; SCC vertex -&gt; SCC vertex -&gt; Bool
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: SCC vertex -&gt; SCC vertex -&gt; Bool
$c/= :: forall vertex. Eq vertex =&gt; SCC vertex -&gt; SCC vertex -&gt; Bool
== :: SCC vertex -&gt; SCC vertex -&gt; Bool
$c== :: forall vertex. Eq vertex =&gt; SCC vertex -&gt; SCC vertex -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span>   </span><span class="hs-comment">-- ^ @since 0.5.9</span><span>
</span><span id="line-154"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679173168"><span id="local-6989586621679173170"><span id="local-6989586621679173178"><span class="annot"><span class="annottext">Int -&gt; SCC vertex -&gt; ShowS
[SCC vertex] -&gt; ShowS
SCC vertex -&gt; String
(Int -&gt; SCC vertex -&gt; ShowS)
-&gt; (SCC vertex -&gt; String)
-&gt; ([SCC vertex] -&gt; ShowS)
-&gt; Show (SCC vertex)
forall vertex. Show vertex =&gt; Int -&gt; SCC vertex -&gt; ShowS
forall vertex. Show vertex =&gt; [SCC vertex] -&gt; ShowS
forall vertex. Show vertex =&gt; SCC vertex -&gt; String
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [SCC vertex] -&gt; ShowS
$cshowList :: forall vertex. Show vertex =&gt; [SCC vertex] -&gt; ShowS
show :: SCC vertex -&gt; String
$cshow :: forall vertex. Show vertex =&gt; SCC vertex -&gt; String
showsPrec :: Int -&gt; SCC vertex -&gt; ShowS
$cshowsPrec :: forall vertex. Show vertex =&gt; Int -&gt; SCC vertex -&gt; ShowS
</span><a href="../../base/src/GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span> </span><span class="hs-comment">-- ^ @since 0.5.9</span><span>
</span><span id="line-155"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679173148"><span id="local-6989586621679173160"><span id="local-6989586621679173163"><span id="local-6989586621679173165"><span class="annot"><span class="annottext">ReadPrec [SCC vertex]
ReadPrec (SCC vertex)
Int -&gt; ReadS (SCC vertex)
ReadS [SCC vertex]
(Int -&gt; ReadS (SCC vertex))
-&gt; ReadS [SCC vertex]
-&gt; ReadPrec (SCC vertex)
-&gt; ReadPrec [SCC vertex]
-&gt; Read (SCC vertex)
forall vertex. Read vertex =&gt; ReadPrec [SCC vertex]
forall vertex. Read vertex =&gt; ReadPrec (SCC vertex)
forall vertex. Read vertex =&gt; Int -&gt; ReadS (SCC vertex)
forall vertex. Read vertex =&gt; ReadS [SCC vertex]
forall a.
(Int -&gt; ReadS a)
-&gt; ReadS [a] -&gt; ReadPrec a -&gt; ReadPrec [a] -&gt; Read a
readListPrec :: ReadPrec [SCC vertex]
$creadListPrec :: forall vertex. Read vertex =&gt; ReadPrec [SCC vertex]
readPrec :: ReadPrec (SCC vertex)
$creadPrec :: forall vertex. Read vertex =&gt; ReadPrec (SCC vertex)
readList :: ReadS [SCC vertex]
$creadList :: forall vertex. Read vertex =&gt; ReadS [SCC vertex]
readsPrec :: Int -&gt; ReadS (SCC vertex)
$creadsPrec :: forall vertex. Read vertex =&gt; Int -&gt; ReadS (SCC vertex)
</span><a href="../../base/src/GHC.Read.html#Read"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Read</span></a></span></span></span></span></span><span> </span><span class="hs-comment">-- ^ @since 0.5.9</span><span>
</span><span id="line-156"></span><span>           </span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Eq</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Show</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Read</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-161"></span><span class="hs-identifier">INSTANCE_TYPEABLE1</span><span class="hs-special">(</span><span class="hs-identifier">SCC</span><span class="hs-special">)</span><span class="hs-cpp">

#ifdef __GLASGOW_HASKELL__
</span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-165"></span><span id="local-6989586621679173106"><span id="local-6989586621679173108"><span id="local-6989586621679173110"><span id="local-6989586621679173112"><span id="local-6989586621679173114"><span id="local-6989586621679173116"><span id="local-6989586621679173118"><span id="local-6989586621679173120"><span id="local-6989586621679173122"><span id="local-6989586621679173128"><span id="local-6989586621679173130"><span id="local-6989586621679173132"><span id="local-6989586621679173136"><span id="local-6989586621679173141"><span id="local-6989586621679173570"><span class="hs-keyword">deriving</span><span> </span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../base/src/Data.Data.html#Data"><span class="hs-identifier hs-type">Data</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173570"><span class="hs-identifier hs-type">vertex</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../base/src/Data.Data.html#Data"><span class="hs-identifier hs-type">Data</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173570"><span class="hs-identifier hs-type">vertex</span></a></span><span class="hs-special">)</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span>
</span><span id="line-166"></span><span>
</span><span id="line-167"></span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-168"></span><span class="hs-keyword">deriving</span><span> </span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../base/src/GHC.Generics.html#Generic1"><span class="hs-identifier hs-type">Generic1</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span>
</span><span id="line-169"></span><span>
</span><span id="line-170"></span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-171"></span><span id="local-6989586621679173566"><span class="hs-keyword">deriving</span><span> </span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../base/src/GHC.Generics.html#Generic"><span class="hs-identifier hs-type">Generic</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173566"><span class="hs-identifier hs-type">vertex</span></a></span><span class="hs-special">)</span></span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">
#if MIN_VERSION_base(4,9,0)
</span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-176"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../base/src/Data.Functor.Classes.html#Eq1"><span class="hs-identifier hs-type">Eq1</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-177"></span><span>  </span><span id="local-6989586621679173091"><span class="annot"><span class="annottext">liftEq :: forall a b. (a -&gt; b -&gt; Bool) -&gt; SCC a -&gt; SCC b -&gt; Bool
</span><a href="../../base/src/Data.Functor.Classes.html#liftEq"><span class="hs-identifier hs-var hs-var hs-var hs-var">liftEq</span></a></span></span><span> </span><span id="local-6989586621679173089"><span class="annot"><span class="annottext">a -&gt; b -&gt; Bool
</span><a href="#local-6989586621679173089"><span class="hs-identifier hs-var">eq</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679173088"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679173088"><span class="hs-identifier hs-var">v1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679173087"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679173087"><span class="hs-identifier hs-var">v2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; Bool
</span><a href="#local-6989586621679173089"><span class="hs-identifier hs-var">eq</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679173088"><span class="hs-identifier hs-var">v1</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679173087"><span class="hs-identifier hs-var">v2</span></a></span><span>
</span><span id="line-178"></span><span>  </span><span class="annot"><a href="../../base/src/Data.Functor.Classes.html#liftEq"><span class="hs-identifier hs-var">liftEq</span></a></span><span> </span><span id="local-6989586621679173086"><span class="annot"><span class="annottext">a -&gt; b -&gt; Bool
</span><a href="#local-6989586621679173086"><span class="hs-identifier hs-var">eq</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679173085"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679173085"><span class="hs-identifier hs-var">vs1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679173084"><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679173084"><span class="hs-identifier hs-var">vs2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b -&gt; Bool) -&gt; [a] -&gt; [b] -&gt; Bool
forall (f :: * -&gt; *) a b.
Eq1 f =&gt;
(a -&gt; b -&gt; Bool) -&gt; f a -&gt; f b -&gt; Bool
</span><a href="../../base/src/Data.Functor.Classes.html#liftEq"><span class="hs-identifier hs-var">liftEq</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; Bool
</span><a href="#local-6989586621679173086"><span class="hs-identifier hs-var">eq</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679173085"><span class="hs-identifier hs-var">vs1</span></a></span><span> </span><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679173084"><span class="hs-identifier hs-var">vs2</span></a></span><span>
</span><span id="line-179"></span><span>  </span><span class="annot"><a href="../../base/src/Data.Functor.Classes.html#liftEq"><span class="hs-identifier hs-var">liftEq</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">SCC a
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">SCC b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-180"></span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-181"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679173081"><span class="annot"><a href="../../base/src/Data.Functor.Classes.html#Show1"><span class="hs-identifier hs-type">Show1</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-182"></span><span>  </span><span id="local-6989586621679173079"><span class="annot"><span class="annottext">liftShowsPrec :: forall a.
(Int -&gt; a -&gt; ShowS) -&gt; ([a] -&gt; ShowS) -&gt; Int -&gt; SCC a -&gt; ShowS
</span><a href="../../base/src/Data.Functor.Classes.html#liftShowsPrec"><span class="hs-identifier hs-var hs-var hs-var hs-var">liftShowsPrec</span></a></span></span><span> </span><span id="local-6989586621679173077"><span class="annot"><span class="annottext">Int -&gt; a -&gt; ShowS
</span><a href="#local-6989586621679173077"><span class="hs-identifier hs-var">sp</span></a></span></span><span> </span><span id="local-6989586621679173076"><span class="annot"><span class="annottext">[a] -&gt; ShowS
</span><a href="#local-6989586621679173076"><span class="hs-identifier hs-var">_sl</span></a></span></span><span> </span><span id="local-6989586621679173075"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679173075"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679173074"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679173074"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; a -&gt; ShowS) -&gt; String -&gt; Int -&gt; a -&gt; ShowS
forall a. (Int -&gt; a -&gt; ShowS) -&gt; String -&gt; Int -&gt; a -&gt; ShowS
</span><a href="../../base/src/Data.Functor.Classes.html#showsUnaryWith"><span class="hs-identifier hs-var">showsUnaryWith</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; a -&gt; ShowS
</span><a href="#local-6989586621679173077"><span class="hs-identifier hs-var">sp</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;AcyclicSCC&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679173075"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679173074"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-183"></span><span>  </span><span class="annot"><a href="../../base/src/Data.Functor.Classes.html#liftShowsPrec"><span class="hs-identifier hs-var">liftShowsPrec</span></a></span><span> </span><span id="local-6989586621679173072"><span class="annot"><span class="annottext">Int -&gt; a -&gt; ShowS
</span><a href="#local-6989586621679173072"><span class="hs-identifier hs-var">_sp</span></a></span></span><span> </span><span id="local-6989586621679173071"><span class="annot"><span class="annottext">[a] -&gt; ShowS
</span><a href="#local-6989586621679173071"><span class="hs-identifier hs-var">sl</span></a></span></span><span> </span><span id="local-6989586621679173070"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679173070"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679173069"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679173069"><span class="hs-identifier hs-var">vs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; [a] -&gt; ShowS) -&gt; String -&gt; Int -&gt; [a] -&gt; ShowS
forall a. (Int -&gt; a -&gt; ShowS) -&gt; String -&gt; Int -&gt; a -&gt; ShowS
</span><a href="../../base/src/Data.Functor.Classes.html#showsUnaryWith"><span class="hs-identifier hs-var">showsUnaryWith</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">([a] -&gt; ShowS) -&gt; Int -&gt; [a] -&gt; ShowS
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; ShowS
</span><a href="#local-6989586621679173071"><span class="hs-identifier hs-var">sl</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CyclicSCC&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679173070"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679173069"><span class="hs-identifier hs-var">vs</span></a></span><span>
</span><span id="line-184"></span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-185"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679173061"><span id="local-6989586621679173063"><span id="local-6989586621679173065"><span class="annot"><a href="../../base/src/Data.Functor.Classes.html#Read1"><span class="hs-identifier hs-type">Read1</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-186"></span><span>  </span><span id="local-6989586621679173054"><span class="annot"><span class="annottext">liftReadsPrec :: forall a. (Int -&gt; ReadS a) -&gt; ReadS [a] -&gt; Int -&gt; ReadS (SCC a)
</span><a href="../../base/src/Data.Functor.Classes.html#liftReadsPrec"><span class="hs-identifier hs-var hs-var hs-var hs-var">liftReadsPrec</span></a></span></span><span> </span><span id="local-6989586621679173052"><span class="annot"><span class="annottext">Int -&gt; ReadS a
</span><a href="#local-6989586621679173052"><span class="hs-identifier hs-var">rp</span></a></span></span><span> </span><span id="local-6989586621679173051"><span class="annot"><span class="annottext">ReadS [a]
</span><a href="#local-6989586621679173051"><span class="hs-identifier hs-var">rl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(String -&gt; ReadS (SCC a)) -&gt; Int -&gt; ReadS (SCC a)
forall a. (String -&gt; ReadS a) -&gt; Int -&gt; ReadS a
</span><a href="../../base/src/Data.Functor.Classes.html#readsData"><span class="hs-identifier hs-var">readsData</span></a></span><span> </span><span class="annot"><span class="annottext">((String -&gt; ReadS (SCC a)) -&gt; Int -&gt; ReadS (SCC a))
-&gt; (String -&gt; ReadS (SCC a)) -&gt; Int -&gt; ReadS (SCC a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-187"></span><span>    </span><span class="annot"><span class="annottext">(Int -&gt; ReadS a)
-&gt; String -&gt; (a -&gt; SCC a) -&gt; String -&gt; ReadS (SCC a)
forall a t.
(Int -&gt; ReadS a) -&gt; String -&gt; (a -&gt; t) -&gt; String -&gt; ReadS t
</span><a href="../../base/src/Data.Functor.Classes.html#readsUnaryWith"><span class="hs-identifier hs-var">readsUnaryWith</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; ReadS a
</span><a href="#local-6989586621679173052"><span class="hs-identifier hs-var">rp</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;AcyclicSCC&quot;</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; SCC a
forall vertex. vertex -&gt; SCC vertex
</span><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-var">AcyclicSCC</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; ReadS (SCC a))
-&gt; (String -&gt; ReadS (SCC a)) -&gt; String -&gt; ReadS (SCC a)
forall a. Semigroup a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span>
</span><span id="line-188"></span><span>    </span><span class="annot"><span class="annottext">(Int -&gt; ReadS [a])
-&gt; String -&gt; ([a] -&gt; SCC a) -&gt; String -&gt; ReadS (SCC a)
forall a t.
(Int -&gt; ReadS a) -&gt; String -&gt; (a -&gt; t) -&gt; String -&gt; ReadS t
</span><a href="../../base/src/Data.Functor.Classes.html#readsUnaryWith"><span class="hs-identifier hs-var">readsUnaryWith</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ReadS [a] -&gt; Int -&gt; ReadS [a]
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">ReadS [a]
</span><a href="#local-6989586621679173051"><span class="hs-identifier hs-var">rl</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CyclicSCC&quot;</span></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; SCC a
forall vertex. [vertex] -&gt; SCC vertex
</span><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-191"></span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-192"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679173016"><span id="local-6989586621679173018"><span id="local-6989586621679173020"><span id="local-6989586621679173022"><span id="local-6989586621679173024"><span id="local-6989586621679173026"><span id="local-6989586621679173028"><span id="local-6989586621679173030"><span id="local-6989586621679173032"><span id="local-6989586621679173034"><span id="local-6989586621679173036"><span id="local-6989586621679173038"><span id="local-6989586621679173040"><span id="local-6989586621679173043"><span id="local-6989586621679173045"><span id="local-6989586621679173047"><span class="annot"><a href="../../base/src/Data.Foldable.html#Foldable"><span class="hs-identifier hs-type">F.Foldable</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-193"></span><span>  </span><span id="local-6989586621679173013"><span class="annot"><span class="annottext">foldr :: forall a b. (a -&gt; b -&gt; b) -&gt; b -&gt; SCC a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var hs-var hs-var hs-var">foldr</span></a></span></span><span> </span><span id="local-6989586621679173011"><span class="annot"><span class="annottext">a -&gt; b -&gt; b
</span><a href="#local-6989586621679173011"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span id="local-6989586621679173010"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679173010"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679173009"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679173009"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; b
</span><a href="#local-6989586621679173011"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679173009"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679173010"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-194"></span><span>  </span><span class="annot"><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span id="local-6989586621679173008"><span class="annot"><span class="annottext">a -&gt; b -&gt; b
</span><a href="#local-6989586621679173008"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span id="local-6989586621679173007"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679173007"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679173006"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679173006"><span class="hs-identifier hs-var">vs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; b
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; b
</span><a href="#local-6989586621679173008"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679173007"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679173006"><span class="hs-identifier hs-var">vs</span></a></span><span>
</span><span id="line-195"></span><span>
</span><span id="line-196"></span><span class="hs-comment">-- | @since 0.5.9</span><span>
</span><span id="line-197"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679172995"><span id="local-6989586621679172997"><span id="local-6989586621679172999"><span class="annot"><a href="../../base/src/Data.Traversable.html#Traversable"><span class="hs-identifier hs-type">Traversable</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-198"></span><span>  </span><span class="hs-comment">-- We treat the non-empty cyclic case specially to cut one</span><span>
</span><span id="line-199"></span><span>  </span><span class="hs-comment">-- fmap application.</span><span>
</span><span id="line-200"></span><span>  </span><span id="local-6989586621679172984"><span class="annot"><span class="annottext">traverse :: forall (f :: * -&gt; *) a b.
Applicative f =&gt;
(a -&gt; f b) -&gt; SCC a -&gt; f (SCC b)
</span><a href="../../base/src/Data.Traversable.html#traverse"><span class="hs-identifier hs-var hs-var hs-var hs-var">traverse</span></a></span></span><span> </span><span id="local-6989586621679172982"><span class="annot"><span class="annottext">a -&gt; f b
</span><a href="#local-6989586621679172982"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679172981"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172981"><span class="hs-identifier hs-var">vertex</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">b -&gt; SCC b
forall vertex. vertex -&gt; SCC vertex
</span><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-var">AcyclicSCC</span></a></span><span> </span><span class="annot"><span class="annottext">(b -&gt; SCC b) -&gt; f b -&gt; f (SCC b)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; f b
</span><a href="#local-6989586621679172982"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172981"><span class="hs-identifier hs-var">vertex</span></a></span><span>
</span><span id="line-201"></span><span>  </span><span class="annot"><a href="../../base/src/Data.Traversable.html#traverse"><span class="hs-identifier hs-var">traverse</span></a></span><span> </span><span id="local-6989586621679172979"><span class="annot"><span class="annottext">a -&gt; f b
</span><a href="#local-6989586621679172979"><span class="hs-identifier hs-var">_f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SCC b -&gt; f (SCC b)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[b] -&gt; SCC b
forall vertex. [vertex] -&gt; SCC vertex
</span><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-202"></span><span>  </span><span class="annot"><a href="../../base/src/Data.Traversable.html#traverse"><span class="hs-identifier hs-var">traverse</span></a></span><span> </span><span id="local-6989586621679172978"><span class="annot"><span class="annottext">a -&gt; f b
</span><a href="#local-6989586621679172978"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172977"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172977"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621679172976"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679172976"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-203"></span><span>    </span><span class="annot"><span class="annottext">(b -&gt; [b] -&gt; SCC b) -&gt; f b -&gt; f [b] -&gt; f (SCC b)
forall (f :: * -&gt; *) a b c.
Applicative f =&gt;
(a -&gt; b -&gt; c) -&gt; f a -&gt; f b -&gt; f c
</span><a href="../../base/src/GHC.Base.html#liftA2"><span class="hs-identifier hs-var">liftA2</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679172974"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679172974"><span class="hs-identifier hs-var">x'</span></a></span></span><span> </span><span id="local-6989586621679172973"><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679172973"><span class="hs-identifier hs-var">xs'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[b] -&gt; SCC b
forall vertex. [vertex] -&gt; SCC vertex
</span><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679172974"><span class="hs-identifier hs-var">x'</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; [b] -&gt; [b]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679172973"><span class="hs-identifier hs-var">xs'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; f b
</span><a href="#local-6989586621679172978"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172977"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(a -&gt; f b) -&gt; [a] -&gt; f [b]
forall (t :: * -&gt; *) (f :: * -&gt; *) a b.
(Traversable t, Applicative f) =&gt;
(a -&gt; f b) -&gt; t a -&gt; f (t b)
</span><a href="../../base/src/Data.Traversable.html#traverse"><span class="hs-identifier hs-var">traverse</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; f b
</span><a href="#local-6989586621679172978"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679172976"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-204"></span><span>
</span><span id="line-205"></span><span id="local-6989586621679173493"><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../deepseq/src/Control.DeepSeq.html#NFData"><span class="hs-identifier hs-type">NFData</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173493"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../deepseq/src/Control.DeepSeq.html#NFData"><span class="hs-identifier hs-type">NFData</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173493"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-206"></span><span>    </span><span id="local-6989586621679172965"><span class="annot"><span class="annottext">rnf :: SCC a -&gt; ()
</span><a href="#local-6989586621679172965"><span class="hs-identifier hs-var hs-var hs-var hs-var">rnf</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679172964"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172964"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; ()
forall a. NFData a =&gt; a -&gt; ()
</span><a href="../../deepseq/src/Control.DeepSeq.html#rnf"><span class="hs-identifier hs-var">rnf</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172964"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-207"></span><span>    </span><span class="annot"><a href="../../deepseq/src/Control.DeepSeq.html#rnf"><span class="hs-identifier hs-var">rnf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679172963"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679172963"><span class="hs-identifier hs-var">vs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; ()
forall a. NFData a =&gt; a -&gt; ()
</span><a href="../../deepseq/src/Control.DeepSeq.html#rnf"><span class="hs-identifier hs-var">rnf</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679172963"><span class="hs-identifier hs-var">vs</span></a></span></span><span>
</span><span id="line-208"></span><span>
</span><span id="line-209"></span><span class="hs-comment">-- | @since 0.5.4</span><span>
</span><span id="line-210"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679172960"><span class="annot"><a href="../../base/src/GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-211"></span><span>    </span><span id="local-6989586621679172956"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; SCC a -&gt; SCC b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span id="local-6989586621679172955"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679172955"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679172954"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172954"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">b -&gt; SCC b
forall vertex. vertex -&gt; SCC vertex
</span><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-var">AcyclicSCC</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679172955"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172954"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-212"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span id="local-6989586621679172953"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679172953"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679172952"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679172952"><span class="hs-identifier hs-var">vs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[b] -&gt; SCC b
forall vertex. [vertex] -&gt; SCC vertex
</span><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; [a] -&gt; [b]
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679172953"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679172952"><span class="hs-identifier hs-var">vs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-213"></span><span>
</span><span id="line-214"></span><span class="hs-comment">-- | The vertices of a list of strongly connected components.</span><span>
</span><span id="line-215"></span><span id="local-6989586621679173484"><span class="annot"><a href="Data.Graph.html#flattenSCCs"><span class="hs-identifier hs-type">flattenSCCs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173484"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173484"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-216"></span><span id="flattenSCCs"><span class="annot"><span class="annottext">flattenSCCs :: forall a. [SCC a] -&gt; [a]
</span><a href="Data.Graph.html#flattenSCCs"><span class="hs-identifier hs-var hs-var">flattenSCCs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(SCC a -&gt; [a]) -&gt; [SCC a] -&gt; [a]
forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
</span><a href="../../base/src/Data.Foldable.html#concatMap"><span class="hs-identifier hs-var">concatMap</span></a></span><span> </span><span class="annot"><span class="annottext">SCC a -&gt; [a]
forall a. SCC a -&gt; [a]
</span><a href="Data.Graph.html#flattenSCC"><span class="hs-identifier hs-var">flattenSCC</span></a></span><span>
</span><span id="line-217"></span><span>
</span><span id="line-218"></span><span class="hs-comment">-- | The vertices of a strongly connected component.</span><span>
</span><span id="line-219"></span><span id="local-6989586621679172949"><span class="annot"><a href="Data.Graph.html#flattenSCC"><span class="hs-identifier hs-type">flattenSCC</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679172949"><span class="hs-identifier hs-type">vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679172949"><span class="hs-identifier hs-type">vertex</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-220"></span><span id="flattenSCC"><span class="annot"><span class="annottext">flattenSCC :: forall a. SCC a -&gt; [a]
</span><a href="Data.Graph.html#flattenSCC"><span class="hs-identifier hs-var hs-var">flattenSCC</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span id="local-6989586621679172948"><span class="annot"><span class="annottext">vertex
</span><a href="#local-6989586621679172948"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">vertex
</span><a href="#local-6989586621679172948"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-221"></span><span class="annot"><a href="Data.Graph.html#flattenSCC"><span class="hs-identifier hs-var">flattenSCC</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679172947"><span class="annot"><span class="annottext">[vertex]
</span><a href="#local-6989586621679172947"><span class="hs-identifier hs-var">vs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[vertex]
</span><a href="#local-6989586621679172947"><span class="hs-identifier hs-var">vs</span></a></span><span>
</span><span id="line-222"></span><span>
</span><span id="line-223"></span><span class="hs-comment">-- | The strongly connected components of a directed graph, reverse topologically</span><span>
</span><span id="line-224"></span><span class="hs-comment">-- sorted.</span><span>
</span><span id="line-225"></span><span class="hs-comment">--</span><span>
</span><span id="line-226"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-227"></span><span class="hs-comment">--</span><span>
</span><span id="line-228"></span><span class="hs-comment">-- &gt; stronglyConnComp [(&quot;a&quot;,0,[1]),(&quot;b&quot;,1,[2,3]),(&quot;c&quot;,2,[1]),(&quot;d&quot;,3,[3])]</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- &gt;   == [CyclicSCC [&quot;d&quot;],CyclicSCC [&quot;b&quot;,&quot;c&quot;],AcyclicSCC &quot;a&quot;]</span><span>
</span><span id="line-230"></span><span id="local-6989586621679173477"><span id="local-6989586621679173478"><span class="annot"><a href="Data.Graph.html#stronglyConnComp"><span class="hs-identifier hs-type">stronglyConnComp</span></a></span><span>
</span><span id="line-231"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Ord</span></span><span> </span><span class="annot"><a href="#local-6989586621679173478"><span class="hs-identifier hs-type">key</span></a></span><span>
</span><span id="line-232"></span><span>        </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679173477"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173478"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173478"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-233"></span><span>                </span><span class="hs-comment">-- ^ The graph: a list of nodes uniquely identified by keys,</span><span>
</span><span id="line-234"></span><span>                </span><span class="hs-comment">-- with a list of keys of nodes this node has edges to.</span><span>
</span><span id="line-235"></span><span>                </span><span class="hs-comment">-- The out-list may contain keys that don't correspond to</span><span>
</span><span id="line-236"></span><span>                </span><span class="hs-comment">-- nodes of the graph; such edges are ignored.</span><span>
</span><span id="line-237"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173477"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">]</span></span></span><span>
</span><span id="line-238"></span><span>
</span><span id="line-239"></span><span id="stronglyConnComp"><span class="annot"><span class="annottext">stronglyConnComp :: forall key node. Ord key =&gt; [(node, key, [key])] -&gt; [SCC node]
</span><a href="Data.Graph.html#stronglyConnComp"><span class="hs-identifier hs-var hs-var">stronglyConnComp</span></a></span></span><span> </span><span id="local-6989586621679172944"><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172944"><span class="hs-identifier hs-var">edges0</span></a></span></span><span>
</span><span id="line-240"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(SCC (node, key, [key]) -&gt; SCC node)
-&gt; [SCC (node, key, [key])] -&gt; [SCC node]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">SCC (node, key, [key]) -&gt; SCC node
forall {vertex} {b} {c}. SCC (vertex, b, c) -&gt; SCC vertex
</span><a href="#local-6989586621679172943"><span class="hs-identifier hs-var">get_node</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[(node, key, [key])] -&gt; [SCC (node, key, [key])]
forall key node.
Ord key =&gt;
[(node, key, [key])] -&gt; [SCC (node, key, [key])]
</span><a href="Data.Graph.html#stronglyConnCompR"><span class="hs-identifier hs-var">stronglyConnCompR</span></a></span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172944"><span class="hs-identifier hs-var">edges0</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-241"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-242"></span><span>    </span><span id="local-6989586621679172943"><span class="annot"><span class="annottext">get_node :: SCC (vertex, b, c) -&gt; SCC vertex
</span><a href="#local-6989586621679172943"><span class="hs-identifier hs-var hs-var">get_node</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-type">AcyclicSCC</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172942"><span class="annot"><span class="annottext">vertex
</span><a href="#local-6989586621679172942"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">c
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">vertex -&gt; SCC vertex
forall vertex. vertex -&gt; SCC vertex
</span><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-var">AcyclicSCC</span></a></span><span> </span><span class="annot"><span class="annottext">vertex
</span><a href="#local-6989586621679172942"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-243"></span><span>    </span><span class="annot"><a href="#local-6989586621679172943"><span class="hs-identifier hs-var">get_node</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-type">CyclicSCC</span></a></span><span> </span><span id="local-6989586621679172941"><span class="annot"><span class="annottext">[(vertex, b, c)]
</span><a href="#local-6989586621679172941"><span class="hs-identifier hs-var">triples</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[vertex] -&gt; SCC vertex
forall vertex. [vertex] -&gt; SCC vertex
</span><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">vertex
</span><a href="#local-6989586621679172940"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172940"><span class="annot"><span class="annottext">vertex
</span><a href="#local-6989586621679172940"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">c
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(vertex, b, c)]
</span><a href="#local-6989586621679172941"><span class="hs-identifier hs-var">triples</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-244"></span><span>
</span><span id="line-245"></span><span class="hs-comment">-- | The strongly connected components of a directed graph, reverse topologically</span><span>
</span><span id="line-246"></span><span class="hs-comment">-- sorted.  The function is the same as 'stronglyConnComp', except that</span><span>
</span><span id="line-247"></span><span class="hs-comment">-- all the information about each node retained.</span><span>
</span><span id="line-248"></span><span class="hs-comment">-- This interface is used when you expect to apply 'SCC' to</span><span>
</span><span id="line-249"></span><span class="hs-comment">-- (some of) the result of 'SCC', so you don't want to lose the</span><span>
</span><span id="line-250"></span><span class="hs-comment">-- dependency information.</span><span>
</span><span id="line-251"></span><span class="hs-comment">--</span><span>
</span><span id="line-252"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-253"></span><span class="hs-comment">--</span><span>
</span><span id="line-254"></span><span class="hs-comment">-- &gt; stronglyConnCompR [(&quot;a&quot;,0,[1]),(&quot;b&quot;,1,[2,3]),(&quot;c&quot;,2,[1]),(&quot;d&quot;,3,[3])]</span><span>
</span><span id="line-255"></span><span class="hs-comment">-- &gt;  == [CyclicSCC [(&quot;d&quot;,3,[3])],CyclicSCC [(&quot;b&quot;,1,[2,3]),(&quot;c&quot;,2,[1])],AcyclicSCC (&quot;a&quot;,0,[1])]</span><span>
</span><span id="line-256"></span><span id="local-6989586621679173468"><span id="local-6989586621679173469"><span class="annot"><a href="Data.Graph.html#stronglyConnCompR"><span class="hs-identifier hs-type">stronglyConnCompR</span></a></span><span>
</span><span id="line-257"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Ord</span></span><span> </span><span class="annot"><a href="#local-6989586621679173469"><span class="hs-identifier hs-type">key</span></a></span><span>
</span><span id="line-258"></span><span>        </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679173468"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173469"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173469"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-259"></span><span>                </span><span class="hs-comment">-- ^ The graph: a list of nodes uniquely identified by keys,</span><span>
</span><span id="line-260"></span><span>                </span><span class="hs-comment">-- with a list of keys of nodes this node has edges to.</span><span>
</span><span id="line-261"></span><span>                </span><span class="hs-comment">-- The out-list may contain keys that don't correspond to</span><span>
</span><span id="line-262"></span><span>                </span><span class="hs-comment">-- nodes of the graph; such edges are ignored.</span><span>
</span><span id="line-263"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#SCC"><span class="hs-identifier hs-type">SCC</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679173468"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173469"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173469"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span></span></span><span>     </span><span class="hs-comment">-- ^ Reverse topologically sorted</span><span>
</span><span id="line-264"></span><span>
</span><span id="line-265"></span><span id="stronglyConnCompR"><span class="annot"><span class="annottext">stronglyConnCompR :: forall key node.
Ord key =&gt;
[(node, key, [key])] -&gt; [SCC (node, key, [key])]
</span><a href="Data.Graph.html#stronglyConnCompR"><span class="hs-identifier hs-var hs-var">stronglyConnCompR</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- added to avoid creating empty array in graphFromEdges -- SOF</span><span>
</span><span id="line-266"></span><span class="annot"><a href="Data.Graph.html#stronglyConnCompR"><span class="hs-identifier hs-var">stronglyConnCompR</span></a></span><span> </span><span id="local-6989586621679172938"><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172938"><span class="hs-identifier hs-var">edges0</span></a></span></span><span>
</span><span id="line-267"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Tree Int -&gt; SCC (node, key, [key]))
-&gt; [Tree Int] -&gt; [SCC (node, key, [key])]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Tree Int -&gt; SCC (node, key, [key])
</span><a href="#local-6989586621679172937"><span class="hs-identifier hs-var">decode</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172936"><span class="hs-identifier hs-var">forest</span></a></span><span>
</span><span id="line-268"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-269"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679172934"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172934"><span class="hs-identifier hs-var">graph</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679172933"><span class="annot"><span class="annottext">Int -&gt; (node, key, [key])
</span><a href="#local-6989586621679172933"><span class="hs-identifier hs-var">vertex_fn</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">key -&gt; Maybe Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
-&gt; (Graph, Int -&gt; (node, key, [key]), key -&gt; Maybe Int)
forall key node.
Ord key =&gt;
[(node, key, [key])]
-&gt; (Graph, Int -&gt; (node, key, [key]), key -&gt; Maybe Int)
</span><a href="Data.Graph.html#graphFromEdges"><span class="hs-identifier hs-var">graphFromEdges</span></a></span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172938"><span class="hs-identifier hs-var">edges0</span></a></span><span>
</span><span id="line-270"></span><span>    </span><span id="local-6989586621679172936"><span class="annot"><span class="annottext">forest :: [Tree Int]
</span><a href="#local-6989586621679172936"><span class="hs-identifier hs-var hs-var">forest</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Tree Int]
</span><a href="Data.Graph.html#scc"><span class="hs-identifier hs-var">scc</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172934"><span class="hs-identifier hs-var">graph</span></a></span><span>
</span><span id="line-271"></span><span>    </span><span id="local-6989586621679172937"><span class="annot"><span class="annottext">decode :: Tree Int -&gt; SCC (node, key, [key])
</span><a href="#local-6989586621679172937"><span class="hs-identifier hs-var hs-var">decode</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172932"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172932"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool
</span><a href="#local-6989586621679172931"><span class="hs-identifier hs-var">mentions_itself</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172932"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])] -&gt; SCC (node, key, [key])
forall vertex. [vertex] -&gt; SCC vertex
</span><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int -&gt; (node, key, [key])
</span><a href="#local-6989586621679172933"><span class="hs-identifier hs-var">vertex_fn</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172932"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-272"></span><span>                       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(node, key, [key]) -&gt; SCC (node, key, [key])
forall vertex. vertex -&gt; SCC vertex
</span><a href="Data.Graph.html#AcyclicSCC"><span class="hs-identifier hs-var">AcyclicSCC</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; (node, key, [key])
</span><a href="#local-6989586621679172933"><span class="hs-identifier hs-var">vertex_fn</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172932"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-273"></span><span>    </span><span class="annot"><a href="#local-6989586621679172937"><span class="hs-identifier hs-var">decode</span></a></span><span> </span><span id="local-6989586621679172930"><span class="annot"><span class="annottext">Tree Int
</span><a href="#local-6989586621679172930"><span class="hs-identifier hs-var">other</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])] -&gt; SCC (node, key, [key])
forall vertex. [vertex] -&gt; SCC vertex
</span><a href="Data.Graph.html#CyclicSCC"><span class="hs-identifier hs-var">CyclicSCC</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tree Int -&gt; [(node, key, [key])] -&gt; [(node, key, [key])]
</span><a href="#local-6989586621679172929"><span class="hs-identifier hs-var">dec</span></a></span><span> </span><span class="annot"><span class="annottext">Tree Int
</span><a href="#local-6989586621679172930"><span class="hs-identifier hs-var">other</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-274"></span><span>                 </span><span class="hs-keyword">where</span><span>
</span><span id="line-275"></span><span>                   </span><span id="local-6989586621679172929"><span class="annot"><span class="annottext">dec :: Tree Int -&gt; [(node, key, [key])] -&gt; [(node, key, [key])]
</span><a href="#local-6989586621679172929"><span class="hs-identifier hs-var hs-var">dec</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172927"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172927"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621679172926"><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172926"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679172925"><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172925"><span class="hs-identifier hs-var">vs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (node, key, [key])
</span><a href="#local-6989586621679172933"><span class="hs-identifier hs-var">vertex_fn</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172927"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">(node, key, [key]) -&gt; [(node, key, [key])] -&gt; [(node, key, [key])]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">(Tree Int -&gt; [(node, key, [key])] -&gt; [(node, key, [key])])
-&gt; [(node, key, [key])] -&gt; [Tree Int] -&gt; [(node, key, [key])]
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">Tree Int -&gt; [(node, key, [key])] -&gt; [(node, key, [key])]
</span><a href="#local-6989586621679172929"><span class="hs-identifier hs-var">dec</span></a></span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172925"><span class="hs-identifier hs-var">vs</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172926"><span class="hs-identifier hs-var">ts</span></a></span><span>
</span><span id="line-276"></span><span>    </span><span id="local-6989586621679172931"><span class="annot"><span class="annottext">mentions_itself :: Int -&gt; Bool
</span><a href="#local-6989586621679172931"><span class="hs-identifier hs-var hs-var">mentions_itself</span></a></span></span><span> </span><span id="local-6989586621679172921"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172921"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172921"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; [Int] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172934"><span class="hs-identifier hs-var">graph</span></a></span><span> </span><span class="annot"><span class="annottext">Graph -&gt; Int -&gt; [Int]
forall i e. Ix i =&gt; Array i e -&gt; i -&gt; e
</span><a href="../../base/src/GHC.Arr.html#%21"><span class="hs-operator hs-var">!</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172921"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-277"></span><span>
</span><span id="line-278"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-279"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-280"></span><span class="hs-comment">--      Graphs</span><span>
</span><span id="line-281"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-282"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-283"></span><span>
</span><span id="line-284"></span><span class="hs-comment">-- | Abstract representation of vertices.</span><span>
</span><span id="line-285"></span><span class="hs-keyword">type</span><span> </span><span id="Vertex"><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-var">Vertex</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-286"></span><span class="hs-comment">-- | Table indexed by a contiguous set of vertices.</span><span>
</span><span id="line-287"></span><span class="hs-comment">--</span><span>
</span><span id="line-288"></span><span class="hs-comment">-- /Note: This is included for backwards compatibility./</span><span>
</span><span id="line-289"></span><span class="hs-keyword">type</span><span> </span><span id="Table"><span class="annot"><a href="Data.Graph.html#Table"><span class="hs-identifier hs-var">Table</span></a></span></span><span> </span><span id="local-6989586621679172918"><span class="annot"><a href="#local-6989586621679172918"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="../../base/src/GHC.Arr.html#Array"><span class="hs-identifier hs-type">Array</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679172918"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-290"></span><span class="hs-comment">-- | Adjacency list representation of a graph, mapping each vertex to its</span><span>
</span><span id="line-291"></span><span class="hs-comment">-- list of successors.</span><span>
</span><span id="line-292"></span><span class="hs-keyword">type</span><span> </span><span id="Graph"><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-var">Graph</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="../../base/src/GHC.Arr.html#Array"><span class="hs-identifier hs-type">Array</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-293"></span><span class="hs-comment">-- | The bounds of an @Array@.</span><span>
</span><span id="line-294"></span><span class="hs-keyword">type</span><span> </span><span id="Bounds"><span class="annot"><a href="Data.Graph.html#Bounds"><span class="hs-identifier hs-var">Bounds</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-295"></span><span class="hs-comment">-- | An edge from the first vertex to the second.</span><span>
</span><span id="line-296"></span><span class="hs-keyword">type</span><span> </span><span id="Edge"><span class="annot"><a href="Data.Graph.html#Edge"><span class="hs-identifier hs-var">Edge</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">)</span><span class="hs-cpp">

#if !USE_UNBOXED_ARRAYS
</span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">UArray</span><span> </span><span class="hs-identifier">i</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Array</span><span> </span><span class="hs-identifier">i</span><span> </span><span class="hs-identifier">a</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-302"></span><span class="hs-comment">-- | Returns the list of vertices in the graph.</span><span>
</span><span id="line-303"></span><span class="hs-comment">--</span><span>
</span><span id="line-304"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-305"></span><span class="hs-comment">--</span><span>
</span><span id="line-306"></span><span class="hs-comment">-- &gt; vertices (buildG (0,-1) []) == []</span><span>
</span><span id="line-307"></span><span class="hs-comment">--</span><span>
</span><span id="line-308"></span><span class="hs-comment">-- &gt; vertices (buildG (0,2) [(0,1),(1,2)]) == [0,1,2]</span><span>
</span><span id="line-309"></span><span class="annot"><a href="Data.Graph.html#vertices"><span class="hs-identifier hs-type">vertices</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-310"></span><span id="vertices"><span class="annot"><span class="annottext">vertices :: Graph -&gt; [Int]
</span><a href="Data.Graph.html#vertices"><span class="hs-identifier hs-var hs-var">vertices</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Int]
forall i e. Ix i =&gt; Array i e -&gt; [i]
</span><a href="../../base/src/GHC.Arr.html#indices"><span class="hs-identifier hs-var">indices</span></a></span><span>
</span><span id="line-311"></span><span>
</span><span id="line-312"></span><span class="hs-comment">-- | Returns the list of edges in the graph.</span><span>
</span><span id="line-313"></span><span class="hs-comment">--</span><span>
</span><span id="line-314"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-315"></span><span class="hs-comment">--</span><span>
</span><span id="line-316"></span><span class="hs-comment">-- &gt; edges (buildG (0,-1) []) == []</span><span>
</span><span id="line-317"></span><span class="hs-comment">--</span><span>
</span><span id="line-318"></span><span class="hs-comment">-- &gt; edges (buildG (0,2) [(0,1),(1,2)]) == [(0,1),(1,2)]</span><span>
</span><span id="line-319"></span><span class="annot"><a href="Data.Graph.html#edges"><span class="hs-identifier hs-type">edges</span></a></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Edge"><span class="hs-identifier hs-type">Edge</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-320"></span><span id="edges"><span class="annot"><span class="annottext">edges :: Graph -&gt; [Edge]
</span><a href="Data.Graph.html#edges"><span class="hs-identifier hs-var hs-var">edges</span></a></span></span><span> </span><span id="local-6989586621679172916"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172916"><span class="hs-identifier hs-var">g</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172915"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172914"><span class="hs-identifier hs-var">w</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621679172915"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172915"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Int]
</span><a href="Data.Graph.html#vertices"><span class="hs-identifier hs-var">vertices</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172916"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679172914"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172914"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172916"><span class="hs-identifier hs-var">g</span></a></span><span class="annot"><span class="annottext">Graph -&gt; Int -&gt; [Int]
forall i e. Ix i =&gt; Array i e -&gt; i -&gt; e
</span><a href="../../base/src/GHC.Arr.html#%21"><span class="hs-operator hs-var">!</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172915"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-321"></span><span>
</span><span id="line-322"></span><span class="hs-comment">-- | Build a graph from a list of edges.</span><span>
</span><span id="line-323"></span><span class="hs-comment">--</span><span>
</span><span id="line-324"></span><span class="hs-comment">-- Warning: This function will cause a runtime exception if a vertex in the edge</span><span>
</span><span id="line-325"></span><span class="hs-comment">-- list is not within the given @Bounds@.</span><span>
</span><span id="line-326"></span><span class="hs-comment">--</span><span>
</span><span id="line-327"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-328"></span><span class="hs-comment">--</span><span>
</span><span id="line-329"></span><span class="hs-comment">-- &gt; buildG (0,-1) [] == array (0,-1) []</span><span>
</span><span id="line-330"></span><span class="hs-comment">-- &gt; buildG (0,2) [(0,1), (1,2)] == array (0,1) [(0,[1]),(1,[2])]</span><span>
</span><span id="line-331"></span><span class="hs-comment">-- &gt; buildG (0,2) [(0,1), (0,2), (1,2)] == array (0,2) [(0,[2,1]),(1,[2]),(2,[])]</span><span>
</span><span id="line-332"></span><span class="annot"><a href="Data.Graph.html#buildG"><span class="hs-identifier hs-type">buildG</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Bounds"><span class="hs-identifier hs-type">Bounds</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Edge"><span class="hs-identifier hs-type">Edge</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span>
</span><span id="line-333"></span><span id="buildG"><span class="annot"><span class="annottext">buildG :: Edge -&gt; [Edge] -&gt; Graph
</span><a href="Data.Graph.html#buildG"><span class="hs-identifier hs-var hs-var">buildG</span></a></span></span><span> </span><span id="local-6989586621679172913"><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172913"><span class="hs-identifier hs-var">bounds0</span></a></span></span><span> </span><span id="local-6989586621679172912"><span class="annot"><span class="annottext">[Edge]
</span><a href="#local-6989586621679172912"><span class="hs-identifier hs-var">edges0</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([Int] -&gt; Int -&gt; [Int]) -&gt; [Int] -&gt; Edge -&gt; [Edge] -&gt; Graph
forall i e a.
Ix i =&gt;
(e -&gt; a -&gt; e) -&gt; e -&gt; (i, i) -&gt; [(i, a)] -&gt; Array i e
</span><a href="../../base/src/GHC.Arr.html#accumArray"><span class="hs-identifier hs-var">accumArray</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Int -&gt; [Int] -&gt; [Int]) -&gt; [Int] -&gt; Int -&gt; [Int]
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">:</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172913"><span class="hs-identifier hs-var">bounds0</span></a></span><span> </span><span class="annot"><span class="annottext">[Edge]
</span><a href="#local-6989586621679172912"><span class="hs-identifier hs-var">edges0</span></a></span><span>
</span><span id="line-334"></span><span>
</span><span id="line-335"></span><span class="hs-comment">-- | The graph obtained by reversing all edges.</span><span>
</span><span id="line-336"></span><span class="hs-comment">--</span><span>
</span><span id="line-337"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-338"></span><span class="hs-comment">--</span><span>
</span><span id="line-339"></span><span class="hs-comment">-- &gt; transposeG (buildG (0,2) [(0,1), (1,2)]) == array (0,2) [(0,[]),(1,[0]),(2,[1])]</span><span>
</span><span id="line-340"></span><span class="annot"><a href="Data.Graph.html#transposeG"><span class="hs-identifier hs-type">transposeG</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span>
</span><span id="line-341"></span><span id="transposeG"><span class="annot"><span class="annottext">transposeG :: Graph -&gt; Graph
</span><a href="Data.Graph.html#transposeG"><span class="hs-identifier hs-var hs-var">transposeG</span></a></span></span><span> </span><span id="local-6989586621679172909"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172909"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [Edge] -&gt; Graph
</span><a href="Data.Graph.html#buildG"><span class="hs-identifier hs-var">buildG</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Edge
forall i e. Array i e -&gt; (i, i)
</span><a href="../../base/src/GHC.Arr.html#bounds"><span class="hs-identifier hs-var">bounds</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172909"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; [Edge]
</span><a href="Data.Graph.html#reverseE"><span class="hs-identifier hs-var">reverseE</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172909"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-342"></span><span>
</span><span id="line-343"></span><span class="annot"><a href="Data.Graph.html#reverseE"><span class="hs-identifier hs-type">reverseE</span></a></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Edge"><span class="hs-identifier hs-type">Edge</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-344"></span><span id="reverseE"><span class="annot"><span class="annottext">reverseE :: Graph -&gt; [Edge]
</span><a href="Data.Graph.html#reverseE"><span class="hs-identifier hs-var hs-var">reverseE</span></a></span></span><span> </span><span id="local-6989586621679172906"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172906"><span class="hs-identifier hs-var">g</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172905"><span class="hs-identifier hs-var">w</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172904"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172904"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172904"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679172905"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172905"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Edge]
</span><a href="Data.Graph.html#edges"><span class="hs-identifier hs-var">edges</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172906"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-345"></span><span>
</span><span id="line-346"></span><span class="hs-comment">-- | A table of the count of edges from each node.</span><span>
</span><span id="line-347"></span><span class="hs-comment">--</span><span>
</span><span id="line-348"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-349"></span><span class="hs-comment">--</span><span>
</span><span id="line-350"></span><span class="hs-comment">-- &gt; outdegree (buildG (0,-1) []) == array (0,-1) []</span><span>
</span><span id="line-351"></span><span class="hs-comment">--</span><span>
</span><span id="line-352"></span><span class="hs-comment">-- &gt; outdegree (buildG (0,2) [(0,1), (1,2)]) == array (0,2) [(0,1),(1,1),(2,0)]</span><span>
</span><span id="line-353"></span><span class="annot"><a href="Data.Graph.html#outdegree"><span class="hs-identifier hs-type">outdegree</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Arr.html#Array"><span class="hs-identifier hs-type">Array</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-354"></span><span class="hs-comment">-- This is bizarrely lazy. We build an array filled with thunks, instead</span><span>
</span><span id="line-355"></span><span class="hs-comment">-- of actually calculating anything. This is the historical behavior, and I</span><span>
</span><span id="line-356"></span><span class="hs-comment">-- suppose someone *could* be relying on it, but it might be worth finding</span><span>
</span><span id="line-357"></span><span class="hs-comment">-- out. Note that we *can't* be so lazy with indegree.</span><span>
</span><span id="line-358"></span><span id="outdegree"><span class="annot"><span class="annottext">outdegree :: Graph -&gt; Array Int Int
</span><a href="Data.Graph.html#outdegree"><span class="hs-identifier hs-var hs-var">outdegree</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([Int] -&gt; Int) -&gt; Graph -&gt; Array Int Int
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span>
</span><span id="line-359"></span><span>
</span><span id="line-360"></span><span class="hs-comment">-- | A table of the count of edges into each node.</span><span>
</span><span id="line-361"></span><span class="hs-comment">--</span><span>
</span><span id="line-362"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-363"></span><span class="hs-comment">--</span><span>
</span><span id="line-364"></span><span class="hs-comment">-- &gt; indegree (buildG (0,-1) []) == array (0,-1) []</span><span>
</span><span id="line-365"></span><span class="hs-comment">--</span><span>
</span><span id="line-366"></span><span class="hs-comment">-- &gt; indegree (buildG (0,2) [(0,1), (1,2)]) == array (0,2) [(0,0),(1,1),(2,1)]</span><span>
</span><span id="line-367"></span><span class="annot"><a href="Data.Graph.html#indegree"><span class="hs-identifier hs-type">indegree</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Arr.html#Array"><span class="hs-identifier hs-type">Array</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-368"></span><span id="indegree"><span class="annot"><span class="annottext">indegree :: Graph -&gt; Array Int Int
</span><a href="Data.Graph.html#indegree"><span class="hs-identifier hs-var hs-var">indegree</span></a></span></span><span> </span><span id="local-6989586621679172902"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172902"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; Int -&gt; Int) -&gt; Int -&gt; Edge -&gt; [Edge] -&gt; Array Int Int
forall i e a.
Ix i =&gt;
(e -&gt; a -&gt; e) -&gt; e -&gt; (i, i) -&gt; [(i, a)] -&gt; Array i e
</span><a href="../../base/src/GHC.Arr.html#accumArray"><span class="hs-identifier hs-var">accumArray</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">(+)</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Edge
forall i e. Array i e -&gt; (i, i)
</span><a href="../../base/src/GHC.Arr.html#bounds"><span class="hs-identifier hs-var">bounds</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172902"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172900"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679172899"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172899"><span class="hs-identifier hs-var">outs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [(Int, [Int])]
forall i e. Ix i =&gt; Array i e -&gt; [(i, e)]
</span><a href="../../base/src/GHC.Arr.html#assocs"><span class="hs-identifier hs-var">assocs</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172902"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679172900"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172900"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172899"><span class="hs-identifier hs-var">outs</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-369"></span><span>
</span><span id="line-370"></span><span class="hs-comment">-- | Identical to 'graphFromEdges', except that the return value</span><span>
</span><span id="line-371"></span><span class="hs-comment">-- does not include the function which maps keys to vertices.  This</span><span>
</span><span id="line-372"></span><span class="hs-comment">-- version of 'graphFromEdges' is for backwards compatibility.</span><span>
</span><span id="line-373"></span><span id="local-6989586621679173444"><span id="local-6989586621679173445"><span class="annot"><a href="Data.Graph.html#graphFromEdges%27"><span class="hs-identifier hs-type">graphFromEdges'</span></a></span><span>
</span><span id="line-374"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Ord</span></span><span> </span><span class="annot"><a href="#local-6989586621679173445"><span class="hs-identifier hs-type">key</span></a></span><span>
</span><span id="line-375"></span><span>        </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679173444"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173445"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173445"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-376"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679173444"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173445"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173445"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-377"></span><span id="graphFromEdges%27"><span class="annot"><span class="annottext">graphFromEdges' :: forall key node.
Ord key =&gt;
[(node, key, [key])] -&gt; (Graph, Int -&gt; (node, key, [key]))
</span><a href="Data.Graph.html#graphFromEdges%27"><span class="hs-identifier hs-var hs-var">graphFromEdges'</span></a></span></span><span> </span><span id="local-6989586621679172896"><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172896"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172895"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int -&gt; (node, key, [key])
</span><a href="#local-6989586621679172894"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-378"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679172895"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172895"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679172894"><span class="annot"><span class="annottext">Int -&gt; (node, key, [key])
</span><a href="#local-6989586621679172894"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">key -&gt; Maybe Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
-&gt; (Graph, Int -&gt; (node, key, [key]), key -&gt; Maybe Int)
forall key node.
Ord key =&gt;
[(node, key, [key])]
-&gt; (Graph, Int -&gt; (node, key, [key]), key -&gt; Maybe Int)
</span><a href="Data.Graph.html#graphFromEdges"><span class="hs-identifier hs-var">graphFromEdges</span></a></span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172896"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-379"></span><span>
</span><span id="line-380"></span><span class="hs-comment">-- | Build a graph from a list of nodes uniquely identified by keys,</span><span>
</span><span id="line-381"></span><span class="hs-comment">-- with a list of keys of nodes this node should have edges to.</span><span>
</span><span id="line-382"></span><span class="hs-comment">--</span><span>
</span><span id="line-383"></span><span class="hs-comment">-- This function takes an adjacency list representing a graph with vertices of</span><span>
</span><span id="line-384"></span><span class="hs-comment">-- type @key@ labeled by values of type @node@ and produces a @Graph@-based</span><span>
</span><span id="line-385"></span><span class="hs-comment">-- representation of that list. The @Graph@ result represents the /shape/ of the</span><span>
</span><span id="line-386"></span><span class="hs-comment">-- graph, and the functions describe a) how to retrieve the label and adjacent</span><span>
</span><span id="line-387"></span><span class="hs-comment">-- vertices of a given vertex, and b) how to retrieve a vertex given a key.</span><span>
</span><span id="line-388"></span><span class="hs-comment">--</span><span>
</span><span id="line-389"></span><span class="hs-comment">-- @(graph, nodeFromVertex, vertexFromKey) = graphFromEdges edgeList@</span><span>
</span><span id="line-390"></span><span class="hs-comment">--</span><span>
</span><span id="line-391"></span><span class="hs-comment">-- * @graph :: Graph@ is the raw, array based adjacency list for the graph.</span><span>
</span><span id="line-392"></span><span class="hs-comment">-- * @nodeFromVertex :: Vertex -&gt; (node, key, [key])@ returns the node</span><span>
</span><span id="line-393"></span><span class="hs-comment">--   associated with the given 0-based @Int@ vertex; see /warning/ below.</span><span>
</span><span id="line-394"></span><span class="hs-comment">-- * @vertexFromKey :: key -&gt; Maybe Vertex@ returns the @Int@ vertex for the</span><span>
</span><span id="line-395"></span><span class="hs-comment">--   key if it exists in the graph, @Nothing@ otherwise.</span><span>
</span><span id="line-396"></span><span class="hs-comment">--</span><span>
</span><span id="line-397"></span><span class="hs-comment">-- To safely use this API you must either extract the list of vertices directly</span><span>
</span><span id="line-398"></span><span class="hs-comment">-- from the graph or first call @vertexFromKey k@ to check if a vertex</span><span>
</span><span id="line-399"></span><span class="hs-comment">-- corresponds to the key @k@. Once it is known that a vertex exists you can use</span><span>
</span><span id="line-400"></span><span class="hs-comment">-- @nodeFromVertex@ to access the labelled node and adjacent vertices. See below</span><span>
</span><span id="line-401"></span><span class="hs-comment">-- for examples.</span><span>
</span><span id="line-402"></span><span class="hs-comment">--</span><span>
</span><span id="line-403"></span><span class="hs-comment">-- Note: The out-list may contain keys that don't correspond to nodes of the</span><span>
</span><span id="line-404"></span><span class="hs-comment">-- graph; they are ignored.</span><span>
</span><span id="line-405"></span><span class="hs-comment">--</span><span>
</span><span id="line-406"></span><span class="hs-comment">-- Warning: The @nodeFromVertex@ function will cause a runtime exception if the</span><span>
</span><span id="line-407"></span><span class="hs-comment">-- given @Vertex@ does not exist.</span><span>
</span><span id="line-408"></span><span class="hs-comment">--</span><span>
</span><span id="line-409"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-410"></span><span class="hs-comment">--</span><span>
</span><span id="line-411"></span><span class="hs-comment">-- An empty graph.</span><span>
</span><span id="line-412"></span><span class="hs-comment">--</span><span>
</span><span id="line-413"></span><span class="hs-comment">-- &gt; (graph, nodeFromVertex, vertexFromKey) = graphFromEdges []</span><span>
</span><span id="line-414"></span><span class="hs-comment">-- &gt; graph = array (0,-1) []</span><span>
</span><span id="line-415"></span><span class="hs-comment">--</span><span>
</span><span id="line-416"></span><span class="hs-comment">-- A graph where the out-list references unspecified nodes (@\'c\'@), these are</span><span>
</span><span id="line-417"></span><span class="hs-comment">-- ignored.</span><span>
</span><span id="line-418"></span><span class="hs-comment">--</span><span>
</span><span id="line-419"></span><span class="hs-comment">-- &gt; (graph, _, _) = graphFromEdges [(&quot;a&quot;, 'a', ['b']), (&quot;b&quot;, 'b', ['c'])]</span><span>
</span><span id="line-420"></span><span class="hs-comment">-- &gt; array (0,1) [(0,[1]),(1,[])]</span><span>
</span><span id="line-421"></span><span class="hs-comment">--</span><span>
</span><span id="line-422"></span><span class="hs-comment">--</span><span>
</span><span id="line-423"></span><span class="hs-comment">-- A graph with 3 vertices: (&quot;a&quot;) -&gt; (&quot;b&quot;) -&gt; (&quot;c&quot;)</span><span>
</span><span id="line-424"></span><span class="hs-comment">--</span><span>
</span><span id="line-425"></span><span class="hs-comment">-- &gt; (graph, nodeFromVertex, vertexFromKey) = graphFromEdges [(&quot;a&quot;, 'a', ['b']), (&quot;b&quot;, 'b', ['c']), (&quot;c&quot;, 'c', [])]</span><span>
</span><span id="line-426"></span><span class="hs-comment">-- &gt; graph == array (0,2) [(0,[1]),(1,[2]),(2,[])]</span><span>
</span><span id="line-427"></span><span class="hs-comment">-- &gt; nodeFromVertex 0 == (&quot;a&quot;,'a',&quot;b&quot;)</span><span>
</span><span id="line-428"></span><span class="hs-comment">-- &gt; vertexFromKey 'a' == Just 0</span><span>
</span><span id="line-429"></span><span class="hs-comment">--</span><span>
</span><span id="line-430"></span><span class="hs-comment">-- Get the label for a given key.</span><span>
</span><span id="line-431"></span><span class="hs-comment">--</span><span>
</span><span id="line-432"></span><span class="hs-comment">-- &gt; let getNodePart (n, _, _) = n</span><span>
</span><span id="line-433"></span><span class="hs-comment">-- &gt; (graph, nodeFromVertex, vertexFromKey) = graphFromEdges [(&quot;a&quot;, 'a', ['b']), (&quot;b&quot;, 'b', ['c']), (&quot;c&quot;, 'c', [])]</span><span>
</span><span id="line-434"></span><span class="hs-comment">-- &gt; getNodePart . nodeFromVertex &lt;$&gt; vertexFromKey 'a' == Just &quot;A&quot;</span><span>
</span><span id="line-435"></span><span class="hs-comment">--</span><span>
</span><span id="line-436"></span><span id="local-6989586621679173462"><span id="local-6989586621679173463"><span class="annot"><a href="Data.Graph.html#graphFromEdges"><span class="hs-identifier hs-type">graphFromEdges</span></a></span><span>
</span><span id="line-437"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Ord</span></span><span> </span><span class="annot"><a href="#local-6989586621679173463"><span class="hs-identifier hs-type">key</span></a></span><span>
</span><span id="line-438"></span><span>        </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679173462"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173463"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173463"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-439"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679173462"><span class="hs-identifier hs-type">node</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173463"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173463"><span class="hs-identifier hs-type">key</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679173463"><span class="hs-identifier hs-type">key</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-440"></span><span id="graphFromEdges"><span class="annot"><span class="annottext">graphFromEdges :: forall key node.
Ord key =&gt;
[(node, key, [key])]
-&gt; (Graph, Int -&gt; (node, key, [key]), key -&gt; Maybe Int)
</span><a href="Data.Graph.html#graphFromEdges"><span class="hs-identifier hs-var hs-var">graphFromEdges</span></a></span></span><span> </span><span id="local-6989586621679172890"><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172890"><span class="hs-identifier hs-var">edges0</span></a></span></span><span>
</span><span id="line-441"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172889"><span class="hs-identifier hs-var">graph</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679172888"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172888"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Array Int (node, key, [key])
</span><a href="#local-6989586621679172887"><span class="hs-identifier hs-var">vertex_map</span></a></span><span> </span><span class="annot"><span class="annottext">Array Int (node, key, [key]) -&gt; Int -&gt; (node, key, [key])
forall i e. Ix i =&gt; Array i e -&gt; i -&gt; e
</span><a href="../../base/src/GHC.Arr.html#%21"><span class="hs-operator hs-var">!</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172888"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">key -&gt; Maybe Int
</span><a href="#local-6989586621679172886"><span class="hs-identifier hs-var">key_vertex</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-442"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-443"></span><span>    </span><span id="local-6989586621679172882"><span class="annot"><span class="annottext">max_v :: Int
</span><a href="#local-6989586621679172882"><span class="hs-identifier hs-var hs-var">max_v</span></a></span></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172890"><span class="hs-identifier hs-var">edges0</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span>
</span><span id="line-444"></span><span>    </span><span id="local-6989586621679172881"><span class="annot"><span class="annottext">bounds0 :: Edge
</span><a href="#local-6989586621679172881"><span class="hs-identifier hs-var hs-var">bounds0</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172882"><span class="hs-identifier hs-var">max_v</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-445"></span><span>    </span><span id="local-6989586621679172879"><span class="annot"><span class="annottext">sorted_edges :: [(node, key, [key])]
</span><a href="#local-6989586621679172879"><span class="hs-identifier hs-var hs-var">sorted_edges</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((node, key, [key]) -&gt; (node, key, [key]) -&gt; Ordering)
-&gt; [(node, key, [key])] -&gt; [(node, key, [key])]
forall a. (a -&gt; a -&gt; Ordering) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/Data.OldList.html#sortBy"><span class="hs-identifier hs-var">sortBy</span></a></span><span> </span><span class="annot"><span class="annottext">(node, key, [key]) -&gt; (node, key, [key]) -&gt; Ordering
forall {a} {a} {c} {a} {c}.
Ord a =&gt;
(a, a, c) -&gt; (a, a, c) -&gt; Ordering
</span><a href="#local-6989586621679172877"><span class="hs-identifier hs-var">lt</span></a></span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172890"><span class="hs-identifier hs-var">edges0</span></a></span><span>
</span><span id="line-446"></span><span>    </span><span id="local-6989586621679172874"><span class="annot"><span class="annottext">edges1 :: [(Int, (node, key, [key]))]
</span><a href="#local-6989586621679172874"><span class="hs-identifier hs-var hs-var">edges1</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int -&gt; (node, key, [key]) -&gt; (Int, (node, key, [key])))
-&gt; [Int] -&gt; [(node, key, [key])] -&gt; [(Int, (node, key, [key]))]
forall a b c. (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]
</span><a href="../../base/src/GHC.List.html#zipWith"><span class="hs-identifier hs-var">zipWith</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">,</span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-glyph">..</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[(node, key, [key])]
</span><a href="#local-6989586621679172879"><span class="hs-identifier hs-var">sorted_edges</span></a></span><span>
</span><span id="line-447"></span><span>
</span><span id="line-448"></span><span>    </span><span id="local-6989586621679172889"><span class="annot"><span class="annottext">graph :: Graph
</span><a href="#local-6989586621679172889"><span class="hs-identifier hs-var hs-var">graph</span></a></span></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [(Int, [Int])] -&gt; Graph
forall i e. Ix i =&gt; (i, i) -&gt; [(i, e)] -&gt; Array i e
</span><a href="../../base/src/GHC.Arr.html#array"><span class="hs-identifier hs-var">array</span></a></span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172881"><span class="hs-identifier hs-var">bounds0</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-special">,</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172870"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(key -&gt; Maybe Int) -&gt; [key] -&gt; [Int]
forall a b. (a -&gt; Maybe b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/Data.Maybe.html#mapMaybe"><span class="hs-identifier hs-var">mapMaybe</span></a></span><span> </span><span class="annot"><span class="annottext">key -&gt; Maybe Int
</span><a href="#local-6989586621679172886"><span class="hs-identifier hs-var">key_vertex</span></a></span><span> </span><span class="annot"><span class="annottext">[key]
</span><a href="#local-6989586621679172868"><span class="hs-identifier hs-var">ks</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="hs-special">,</span><span class="hs-special">)</span><span> </span><span id="local-6989586621679172870"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172870"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">node
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span>    </span><span class="annot"><span class="annottext">key
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679172868"><span class="annot"><span class="annottext">[key]
</span><a href="#local-6989586621679172868"><span class="hs-identifier hs-var">ks</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Int, (node, key, [key]))]
</span><a href="#local-6989586621679172874"><span class="hs-identifier hs-var">edges1</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-449"></span><span>    </span><span id="local-6989586621679172866"><span class="annot"><span class="annottext">key_map :: Array Int key
</span><a href="#local-6989586621679172866"><span class="hs-identifier hs-var hs-var">key_map</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [(Int, key)] -&gt; Array Int key
forall i e. Ix i =&gt; (i, i) -&gt; [(i, e)] -&gt; Array i e
</span><a href="../../base/src/GHC.Arr.html#array"><span class="hs-identifier hs-var">array</span></a></span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172881"><span class="hs-identifier hs-var">bounds0</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-special">,</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172865"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">key
</span><a href="#local-6989586621679172864"><span class="hs-identifier hs-var">k</span></a></span><span>                       </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="hs-special">,</span><span class="hs-special">)</span><span> </span><span id="local-6989586621679172865"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172865"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">node
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span>    </span><span id="local-6989586621679172864"><span class="annot"><span class="annottext">key
</span><a href="#local-6989586621679172864"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[key]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Int, (node, key, [key]))]
</span><a href="#local-6989586621679172874"><span class="hs-identifier hs-var">edges1</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-450"></span><span>    </span><span id="local-6989586621679172887"><span class="annot"><span class="annottext">vertex_map :: Array Int (node, key, [key])
</span><a href="#local-6989586621679172887"><span class="hs-identifier hs-var hs-var">vertex_map</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [(Int, (node, key, [key]))] -&gt; Array Int (node, key, [key])
forall i e. Ix i =&gt; (i, i) -&gt; [(i, e)] -&gt; Array i e
</span><a href="../../base/src/GHC.Arr.html#array"><span class="hs-identifier hs-var">array</span></a></span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172881"><span class="hs-identifier hs-var">bounds0</span></a></span><span> </span><span class="annot"><span class="annottext">[(Int, (node, key, [key]))]
</span><a href="#local-6989586621679172874"><span class="hs-identifier hs-var">edges1</span></a></span><span>
</span><span id="line-451"></span><span>
</span><span id="line-452"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621679172860"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172860"><span class="hs-identifier hs-var">k1</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">c
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679172877"><span class="annot"><span class="annottext">lt :: (a, a, c) -&gt; (a, a, c) -&gt; Ordering
</span><a href="#local-6989586621679172877"><span class="hs-operator hs-var hs-var">`lt`</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621679172859"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172859"><span class="hs-identifier hs-var">k2</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">c
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172860"><span class="hs-identifier hs-var">k1</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Ordering
forall a. Ord a =&gt; a -&gt; a -&gt; Ordering
</span><span class="hs-operator hs-var">`compare`</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172859"><span class="hs-identifier hs-var">k2</span></a></span><span>
</span><span id="line-453"></span><span>
</span><span id="line-454"></span><span>    </span><span class="hs-comment">-- key_vertex :: key -&gt; Maybe Vertex</span><span>
</span><span id="line-455"></span><span>    </span><span class="hs-comment">--  returns Nothing for non-interesting vertices</span><span>
</span><span id="line-456"></span><span>    </span><span id="local-6989586621679172886"><span class="annot"><span class="annottext">key_vertex :: key -&gt; Maybe Int
</span><a href="#local-6989586621679172886"><span class="hs-identifier hs-var hs-var">key_vertex</span></a></span></span><span> </span><span id="local-6989586621679172857"><span class="annot"><span class="annottext">key
</span><a href="#local-6989586621679172857"><span class="hs-identifier hs-var">k</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Maybe Int
</span><a href="#local-6989586621679172856"><span class="hs-identifier hs-var">findVertex</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172882"><span class="hs-identifier hs-var">max_v</span></a></span><span>
</span><span id="line-457"></span><span>                   </span><span class="hs-keyword">where</span><span>
</span><span id="line-458"></span><span>                     </span><span id="local-6989586621679172856"><span class="annot"><span class="annottext">findVertex :: Int -&gt; Int -&gt; Maybe Int
</span><a href="#local-6989586621679172856"><span class="hs-identifier hs-var hs-var">findVertex</span></a></span></span><span> </span><span id="local-6989586621679172848"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172848"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679172847"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172847"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172848"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172847"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-459"></span><span>                              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Int
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-460"></span><span>                     </span><span class="annot"><a href="#local-6989586621679172856"><span class="hs-identifier hs-var">findVertex</span></a></span><span> </span><span id="local-6989586621679172845"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172845"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679172844"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172844"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">key -&gt; key -&gt; Ordering
forall a. Ord a =&gt; a -&gt; a -&gt; Ordering
</span><span class="hs-identifier hs-var">compare</span></span><span> </span><span class="annot"><span class="annottext">key
</span><a href="#local-6989586621679172857"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Array Int key
</span><a href="#local-6989586621679172866"><span class="hs-identifier hs-var">key_map</span></a></span><span> </span><span class="annot"><span class="annottext">Array Int key -&gt; Int -&gt; key
forall i e. Ix i =&gt; Array i e -&gt; i -&gt; e
</span><a href="../../base/src/GHC.Arr.html#%21"><span class="hs-operator hs-var">!</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172843"><span class="hs-identifier hs-var">mid</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-461"></span><span>                                   </span><span class="annot"><span class="annottext">Ordering
</span><span class="hs-identifier hs-var">LT</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Maybe Int
</span><a href="#local-6989586621679172856"><span class="hs-identifier hs-var">findVertex</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172845"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172843"><span class="hs-identifier hs-var">mid</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-462"></span><span>                                   </span><span class="annot"><span class="annottext">Ordering
</span><span class="hs-identifier hs-var">EQ</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Maybe Int
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172843"><span class="hs-identifier hs-var">mid</span></a></span><span>
</span><span id="line-463"></span><span>                                   </span><span class="annot"><span class="annottext">Ordering
</span><span class="hs-identifier hs-var">GT</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Maybe Int
</span><a href="#local-6989586621679172856"><span class="hs-identifier hs-var">findVertex</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172843"><span class="hs-identifier hs-var">mid</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172844"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-464"></span><span>                              </span><span class="hs-keyword">where</span><span>
</span><span id="line-465"></span><span>                                </span><span id="local-6989586621679172843"><span class="annot"><span class="annottext">mid :: Int
</span><a href="#local-6989586621679172843"><span class="hs-identifier hs-var hs-var">mid</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172845"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172844"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172845"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span>
</span><span id="line-466"></span><span>
</span><span id="line-467"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-468"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-469"></span><span class="hs-comment">--      Depth first search</span><span>
</span><span id="line-470"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-471"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-472"></span><span>
</span><span id="line-473"></span><span class="hs-comment">-- | A spanning forest of the graph, obtained from a depth-first search of</span><span>
</span><span id="line-474"></span><span class="hs-comment">-- the graph starting from each vertex in an unspecified order.</span><span>
</span><span id="line-475"></span><span class="annot"><a href="Data.Graph.html#dff"><span class="hs-identifier hs-type">dff</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span>
</span><span id="line-476"></span><span id="dff"><span class="annot"><span class="annottext">dff :: Graph -&gt; [Tree Int]
</span><a href="Data.Graph.html#dff"><span class="hs-identifier hs-var hs-var">dff</span></a></span></span><span> </span><span id="local-6989586621679172836"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172836"><span class="hs-identifier hs-var">g</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Int] -&gt; [Tree Int]
</span><a href="Data.Graph.html#dfs"><span class="hs-identifier hs-var">dfs</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172836"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; [Int]
</span><a href="Data.Graph.html#vertices"><span class="hs-identifier hs-var">vertices</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172836"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-477"></span><span>
</span><span id="line-478"></span><span class="hs-comment">-- | A spanning forest of the part of the graph reachable from the listed</span><span>
</span><span id="line-479"></span><span class="hs-comment">-- vertices, obtained from a depth-first search of the graph starting at</span><span>
</span><span id="line-480"></span><span class="hs-comment">-- each of the listed vertices in order.</span><span>
</span><span id="line-481"></span><span class="annot"><a href="Data.Graph.html#dfs"><span class="hs-identifier hs-type">dfs</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span>
</span><span id="line-482"></span><span id="dfs"><span class="annot"><span class="annottext">dfs :: Graph -&gt; [Int] -&gt; [Tree Int]
</span><a href="Data.Graph.html#dfs"><span class="hs-identifier hs-var hs-var">dfs</span></a></span></span><span> </span><span id="local-6989586621679172835"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172835"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span id="local-6989586621679172834"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172834"><span class="hs-identifier hs-var">vs</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [Tree Int] -&gt; [Tree Int]
</span><a href="Data.Graph.html#prune"><span class="hs-identifier hs-var">prune</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Edge
forall i e. Array i e -&gt; (i, i)
</span><a href="../../base/src/GHC.Arr.html#bounds"><span class="hs-identifier hs-var">bounds</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172835"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Int -&gt; Tree Int) -&gt; [Int] -&gt; [Tree Int]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Int -&gt; Tree Int
</span><a href="Data.Graph.html#generate"><span class="hs-identifier hs-var">generate</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172835"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172834"><span class="hs-identifier hs-var">vs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-483"></span><span>
</span><span id="line-484"></span><span class="annot"><a href="Data.Graph.html#generate"><span class="hs-identifier hs-type">generate</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span>
</span><span id="line-485"></span><span id="generate"><span class="annot"><span class="annottext">generate :: Graph -&gt; Int -&gt; Tree Int
</span><a href="Data.Graph.html#generate"><span class="hs-identifier hs-var hs-var">generate</span></a></span></span><span> </span><span id="local-6989586621679172831"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172831"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span id="local-6989586621679172830"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172830"><span class="hs-identifier hs-var">v</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; [Tree Int] -&gt; Tree Int
forall a. a -&gt; [Tree a] -&gt; Tree a
</span><a href="Data.Tree.html#Node"><span class="hs-identifier hs-var">Node</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172830"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Int -&gt; Tree Int) -&gt; [Int] -&gt; [Tree Int]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Int -&gt; Tree Int
</span><a href="Data.Graph.html#generate"><span class="hs-identifier hs-var">generate</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172831"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172831"><span class="hs-identifier hs-var">g</span></a></span><span class="annot"><span class="annottext">Graph -&gt; Int -&gt; [Int]
forall i e. Ix i =&gt; Array i e -&gt; i -&gt; e
</span><a href="../../base/src/GHC.Arr.html#%21"><span class="hs-operator hs-var">!</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172830"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-486"></span><span>
</span><span id="line-487"></span><span class="annot"><a href="Data.Graph.html#prune"><span class="hs-identifier hs-type">prune</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Bounds"><span class="hs-identifier hs-type">Bounds</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span>
</span><span id="line-488"></span><span id="prune"><span class="annot"><span class="annottext">prune :: Edge -&gt; [Tree Int] -&gt; [Tree Int]
</span><a href="Data.Graph.html#prune"><span class="hs-identifier hs-var hs-var">prune</span></a></span></span><span> </span><span id="local-6989586621679172829"><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172829"><span class="hs-identifier hs-var">bnds</span></a></span></span><span> </span><span id="local-6989586621679172828"><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172828"><span class="hs-identifier hs-var">ts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; (forall s. SetM s [Tree Int]) -&gt; [Tree Int]
forall a. Edge -&gt; (forall s. SetM s a) -&gt; a
</span><a href="Data.Graph.html#run"><span class="hs-identifier hs-var">run</span></a></span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172829"><span class="hs-identifier hs-var">bnds</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Tree Int] -&gt; SetM s [Tree Int]
forall s. [Tree Int] -&gt; SetM s [Tree Int]
</span><a href="Data.Graph.html#chop"><span class="hs-identifier hs-var">chop</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172828"><span class="hs-identifier hs-var">ts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-489"></span><span>
</span><span id="line-490"></span><span id="local-6989586621679173419"><span class="annot"><a href="Data.Graph.html#chop"><span class="hs-identifier hs-type">chop</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173419"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-491"></span><span id="chop"><span class="annot"><span class="annottext">chop :: forall s. [Tree Int] -&gt; SetM s [Tree Int]
</span><a href="Data.Graph.html#chop"><span class="hs-identifier hs-var hs-var">chop</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Tree Int] -&gt; SetM s [Tree Int]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-492"></span><span class="annot"><a href="Data.Graph.html#chop"><span class="hs-identifier hs-var">chop</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172819"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172819"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621679172818"><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172818"><span class="hs-identifier hs-var">ts</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621679172817"><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172817"><span class="hs-identifier hs-var">us</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-493"></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-494"></span><span>                </span><span id="local-6989586621679172816"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679172816"><span class="hs-identifier hs-var">visited</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; SetM s Bool
forall s. Int -&gt; SetM s Bool
</span><a href="Data.Graph.html#contains"><span class="hs-identifier hs-var">contains</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172819"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-495"></span><span>                </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679172816"><span class="hs-identifier hs-var">visited</span></a></span><span> </span><span class="hs-keyword">then</span><span>
</span><span id="line-496"></span><span>                  </span><span class="annot"><span class="annottext">[Tree Int] -&gt; SetM s [Tree Int]
forall s. [Tree Int] -&gt; SetM s [Tree Int]
</span><a href="Data.Graph.html#chop"><span class="hs-identifier hs-var">chop</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172817"><span class="hs-identifier hs-var">us</span></a></span><span>
</span><span id="line-497"></span><span>                 </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-498"></span><span>                  </span><span class="annot"><span class="annottext">Int -&gt; SetM s ()
forall s. Int -&gt; SetM s ()
</span><a href="Data.Graph.html#include"><span class="hs-identifier hs-var">include</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172819"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-499"></span><span>                  </span><span id="local-6989586621679172813"><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172813"><span class="hs-keyword hs-var">as</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Tree Int] -&gt; SetM s [Tree Int]
forall s. [Tree Int] -&gt; SetM s [Tree Int]
</span><a href="Data.Graph.html#chop"><span class="hs-identifier hs-var">chop</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172818"><span class="hs-identifier hs-var">ts</span></a></span><span>
</span><span id="line-500"></span><span>                  </span><span id="local-6989586621679172812"><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172812"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Tree Int] -&gt; SetM s [Tree Int]
forall s. [Tree Int] -&gt; SetM s [Tree Int]
</span><a href="Data.Graph.html#chop"><span class="hs-identifier hs-var">chop</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172817"><span class="hs-identifier hs-var">us</span></a></span><span>
</span><span id="line-501"></span><span>                  </span><span class="annot"><span class="annottext">[Tree Int] -&gt; SetM s [Tree Int]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; [Tree Int] -&gt; Tree Int
forall a. a -&gt; [Tree a] -&gt; Tree a
</span><a href="Data.Tree.html#Node"><span class="hs-identifier hs-var">Node</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172819"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172813"><span class="hs-keyword hs-var">as</span></a></span><span> </span><span class="annot"><span class="annottext">Tree Int -&gt; [Tree Int] -&gt; [Tree Int]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172812"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-502"></span><span>
</span><span id="line-503"></span><span class="hs-comment">-- A monad holding a set of vertices visited so far.</span><span class="hs-cpp">
#if USE_ST_MONAD
</span><span>
</span><span id="line-506"></span><span class="hs-comment">-- Use the ST monad if available, for constant-time primitives.</span><span class="hs-cpp">

#if USE_UNBOXED_ARRAYS
</span><span class="hs-keyword">newtype</span><span> </span><span id="SetM"><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span></span><span> </span><span id="local-6989586621679173412"><span class="annot"><a href="#local-6989586621679173412"><span class="hs-identifier hs-type">s</span></a></span></span><span> </span><span id="local-6989586621679173411"><span class="annot"><a href="#local-6989586621679173411"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="SetM"><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="runSetM"><span class="annot"><span class="annottext">forall s a. SetM s a -&gt; STUArray s Int Bool -&gt; ST s a
</span><a href="Data.Graph.html#runSetM"><span class="hs-identifier hs-var hs-var">runSetM</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Base.html#STUArray"><span class="hs-identifier hs-type">STUArray</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173412"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173412"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173411"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">newtype</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">runSetM</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">STArray</span><span>  </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">Vertex</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">ST</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-special">}</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-514"></span><span id="local-6989586621679173417"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679172805"><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173417"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-515"></span><span>    </span><span id="local-6989586621679172801"><span class="annot"><span class="annottext">return :: forall a. a -&gt; SetM s a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var hs-var hs-var hs-var">return</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; SetM s a
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span>
</span><span id="line-516"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#return"><span class="hs-pragma hs-type">return</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-517"></span><span>    </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span id="local-6989586621679172798"><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s a
</span><a href="#local-6989586621679172798"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621679172797"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b. SetM s a -&gt; (a -&gt; SetM s b) -&gt; SetM s b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span id="local-6989586621679172796"><span class="annot"><span class="annottext">a -&gt; SetM s b
</span><a href="#local-6989586621679172796"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b
forall s a. (STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
</span><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span><span> </span><span class="annot"><span class="annottext">((STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b)
-&gt; (STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679172795"><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172795"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621679172794"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172794"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s a
</span><a href="#local-6989586621679172798"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172795"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">SetM s b -&gt; STUArray s Int Bool -&gt; ST s b
forall s a. SetM s a -&gt; STUArray s Int Bool -&gt; ST s a
</span><a href="Data.Graph.html#runSetM"><span class="hs-identifier hs-var hs-var">runSetM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; SetM s b
</span><a href="#local-6989586621679172796"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172794"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172795"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-518"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&gt;&gt;=</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span></span><span>
</span><span id="line-519"></span><span>
</span><span id="line-520"></span><span id="local-6989586621679173398"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679172791"><span class="annot"><a href="../../base/src/GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173398"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-521"></span><span>    </span><span id="local-6989586621679172788"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679172788"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679172787"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; SetM s a -&gt; SetM s b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-operator hs-var hs-var hs-var hs-var">`fmap`</span></a></span></span><span> </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span id="local-6989586621679172786"><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s a
</span><a href="#local-6989586621679172786"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b
forall s a. (STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
</span><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span><span> </span><span class="annot"><span class="annottext">((STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b)
-&gt; (STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679172785"><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172785"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679172788"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; ST s a -&gt; ST s b
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-operator hs-var">`fmap`</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s a
</span><a href="#local-6989586621679172786"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172785"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-522"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-pragma hs-type">fmap</span></a></span><span> </span><span class="hs-pragma">#-}</span></span><span>
</span><span id="line-523"></span><span>
</span><span id="line-524"></span><span id="local-6989586621679172784"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679172774"><span id="local-6989586621679172776"><span id="local-6989586621679172778"><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679172784"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-525"></span><span>    </span><span id="local-6989586621679172771"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; SetM s a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621679172770"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172770"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
forall s a. (STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
</span><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span><span> </span><span class="annot"><span class="annottext">((STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a)
-&gt; (STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ST s a -&gt; STUArray s Int Bool -&gt; ST s a
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; ST s a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172770"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-526"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#pure"><span class="hs-pragma hs-type">pure</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-527"></span><span>    </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span id="local-6989586621679172767"><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s (a -&gt; b)
</span><a href="#local-6989586621679172767"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679172766"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. SetM s (a -&gt; b) -&gt; SetM s a -&gt; SetM s b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;*&gt;</span></a></span></span><span> </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span id="local-6989586621679172765"><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s a
</span><a href="#local-6989586621679172765"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b
forall s a. (STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
</span><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span><span> </span><span class="annot"><span class="annottext">((STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b)
-&gt; (STUArray s Int Bool -&gt; ST s b) -&gt; SetM s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679172764"><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172764"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s (a -&gt; b)
</span><a href="#local-6989586621679172767"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172764"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">ST s (a -&gt; b) -&gt; ((a -&gt; b) -&gt; ST s b) -&gt; ST s b
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; ST s a -&gt; ST s b
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-operator hs-var">`fmap`</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; ST s a
</span><a href="#local-6989586621679172765"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172764"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-528"></span><span>    </span><span class="hs-comment">-- We could also use the following definition</span><span>
</span><span id="line-529"></span><span>    </span><span class="hs-comment">--   SetM f &lt;*&gt; SetM v = SetM $ \s -&gt; f s &lt;*&gt; v s</span><span>
</span><span id="line-530"></span><span>    </span><span class="hs-comment">-- but Applicative (ST s) instance is present only in GHC 7.2+</span><span>
</span><span id="line-531"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&lt;*&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span></span><span>
</span><span id="line-532"></span><span>
</span><span id="line-533"></span><span id="local-6989586621679173421"><span class="annot"><a href="Data.Graph.html#run"><span class="hs-identifier hs-type">run</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Bounds"><span class="hs-identifier hs-type">Bounds</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679173422"><span class="annot"><a href="#local-6989586621679173422"><span class="hs-identifier hs-type">s</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173422"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173421"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679173421"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-534"></span><span id="run"><span class="annot"><span class="annottext">run :: forall a. Edge -&gt; (forall s. SetM s a) -&gt; a
</span><a href="Data.Graph.html#run"><span class="hs-identifier hs-var hs-var">run</span></a></span></span><span> </span><span id="local-6989586621679172763"><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172763"><span class="hs-identifier hs-var">bnds</span></a></span></span><span> </span><span id="local-6989586621679172762"><span class="annot"><span class="annottext">forall s. SetM s a
</span><a href="#local-6989586621679172762"><span class="hs-identifier hs-var">act</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall s. ST s a) -&gt; a
forall a. (forall s. ST s a) -&gt; a
</span><a href="../../base/src/GHC.ST.html#runST"><span class="hs-identifier hs-var">runST</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Edge -&gt; Bool -&gt; ST s (STUArray s Int Bool)
forall (a :: * -&gt; * -&gt; *) e (m :: * -&gt; *) i.
(MArray a e m, Ix i) =&gt;
(i, i) -&gt; e -&gt; m (a i e)
</span><a href="../../array/src/Data.Array.Base.html#newArray"><span class="hs-identifier hs-var">newArray</span></a></span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172763"><span class="hs-identifier hs-var">bnds</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">ST s (STUArray s Int Bool)
-&gt; (STUArray s Int Bool -&gt; ST s a) -&gt; ST s a
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">SetM s a -&gt; STUArray s Int Bool -&gt; ST s a
forall s a. SetM s a -&gt; STUArray s Int Bool -&gt; ST s a
</span><a href="Data.Graph.html#runSetM"><span class="hs-identifier hs-var hs-var">runSetM</span></a></span><span> </span><span class="annot"><span class="annottext">SetM s a
forall s. SetM s a
</span><a href="#local-6989586621679172762"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-535"></span><span>
</span><span id="line-536"></span><span id="local-6989586621679173414"><span class="annot"><a href="Data.Graph.html#contains"><span class="hs-identifier hs-type">contains</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173414"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span></span><span>
</span><span id="line-537"></span><span id="contains"><span class="annot"><span class="annottext">contains :: forall s. Int -&gt; SetM s Bool
</span><a href="Data.Graph.html#contains"><span class="hs-identifier hs-var hs-var">contains</span></a></span></span><span> </span><span id="local-6989586621679172754"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172754"><span class="hs-identifier hs-var">v</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(STUArray s Int Bool -&gt; ST s Bool) -&gt; SetM s Bool
forall s a. (STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
</span><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span><span> </span><span class="annot"><span class="annottext">((STUArray s Int Bool -&gt; ST s Bool) -&gt; SetM s Bool)
-&gt; (STUArray s Int Bool -&gt; ST s Bool) -&gt; SetM s Bool
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679172753"><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172753"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; Int -&gt; ST s Bool
forall (a :: * -&gt; * -&gt; *) e (m :: * -&gt; *) i.
(MArray a e m, Ix i) =&gt;
a i e -&gt; i -&gt; m e
</span><a href="../../array/src/Data.Array.Base.html#readArray"><span class="hs-identifier hs-var">readArray</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172753"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172754"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-538"></span><span>
</span><span id="line-539"></span><span id="local-6989586621679173413"><span class="annot"><a href="Data.Graph.html#include"><span class="hs-identifier hs-type">include</span></a></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-type">SetM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173413"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-540"></span><span id="include"><span class="annot"><span class="annottext">include :: forall s. Int -&gt; SetM s ()
</span><a href="Data.Graph.html#include"><span class="hs-identifier hs-var hs-var">include</span></a></span></span><span> </span><span id="local-6989586621679172750"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172750"><span class="hs-identifier hs-var">v</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(STUArray s Int Bool -&gt; ST s ()) -&gt; SetM s ()
forall s a. (STUArray s Int Bool -&gt; ST s a) -&gt; SetM s a
</span><a href="Data.Graph.html#SetM"><span class="hs-identifier hs-var">SetM</span></a></span><span> </span><span class="annot"><span class="annottext">((STUArray s Int Bool -&gt; ST s ()) -&gt; SetM s ())
-&gt; (STUArray s Int Bool -&gt; ST s ()) -&gt; SetM s ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679172749"><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172749"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool -&gt; Int -&gt; Bool -&gt; ST s ()
forall (a :: * -&gt; * -&gt; *) e (m :: * -&gt; *) i.
(MArray a e m, Ix i) =&gt;
a i e -&gt; i -&gt; e -&gt; m ()
</span><a href="../../array/src/Data.Array.Base.html#writeArray"><span class="hs-identifier hs-var">writeArray</span></a></span><span> </span><span class="annot"><span class="annottext">STUArray s Int Bool
</span><a href="#local-6989586621679172749"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172750"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-cpp">

#else /* !USE_ST_MONAD */
</span><span>
</span><span id="line-544"></span><span class="hs-comment">-- Portable implementation using IntSet.</span><span>
</span><span id="line-545"></span><span>
</span><span id="line-546"></span><span class="hs-keyword">newtype</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">runSetM</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IntSet</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">a</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">IntSet</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-547"></span><span>
</span><span id="line-548"></span><span class="hs-keyword">instance</span><span> </span><span class="hs-identifier">Monad</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-549"></span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">x</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">x</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span>
</span><span id="line-550"></span><span>    </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">x</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s'</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">runSetM</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">s'</span><span>
</span><span id="line-551"></span><span>
</span><span id="line-552"></span><span class="hs-keyword">instance</span><span> </span><span class="hs-identifier">Functor</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-553"></span><span>    </span><span class="hs-identifier">f</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">fmap</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">x</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s'</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s'</span><span class="hs-special">)</span><span>
</span><span id="line-554"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">fmap</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-555"></span><span>
</span><span id="line-556"></span><span class="hs-keyword">instance</span><span> </span><span class="hs-identifier">Applicative</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-557"></span><span>    </span><span class="hs-identifier">pure</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">x</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span>
</span><span id="line-558"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">pure</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-559"></span><span>    </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-operator">&lt;*&gt;</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">k</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s'</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-identifier">s'</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">x</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s''</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">k</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">s''</span><span class="hs-special">)</span><span>
</span><span id="line-560"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&lt;*&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-561"></span><span>
</span><span id="line-562"></span><span class="hs-identifier">run</span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Bounds</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-563"></span><span class="hs-identifier">run</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">act</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fst</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">runSetM</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-identifier">Set.empty</span><span class="hs-special">)</span><span>
</span><span id="line-564"></span><span>
</span><span id="line-565"></span><span class="hs-identifier">contains</span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Vertex</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-566"></span><span class="hs-identifier">contains</span><span> </span><span class="hs-identifier">v</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Set.member</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span>
</span><span id="line-567"></span><span>
</span><span id="line-568"></span><span class="hs-identifier">include</span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Vertex</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-569"></span><span class="hs-identifier">include</span><span> </span><span class="hs-identifier">v</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">SetM</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Set.insert</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span class="hs-cpp">

#endif /* !USE_ST_MONAD */
</span><span>
</span><span id="line-573"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-574"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-575"></span><span class="hs-comment">--      Algorithms</span><span>
</span><span id="line-576"></span><span class="hs-comment">--                                                                      -</span><span>
</span><span id="line-577"></span><span class="hs-comment">-------------------------------------------------------------------------</span><span>
</span><span id="line-578"></span><span>
</span><span id="line-579"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-580"></span><span class="hs-comment">-- Algorithm 1: depth first search numbering</span><span>
</span><span id="line-581"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-582"></span><span>
</span><span id="line-583"></span><span id="local-6989586621679173365"><span class="annot"><a href="Data.Graph.html#preorder%27"><span class="hs-identifier hs-type">preorder'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173365"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173365"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173365"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-584"></span><span id="preorder%27"><span class="annot"><span class="annottext">preorder' :: forall a. Tree a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#preorder%27"><span class="hs-identifier hs-var hs-var">preorder'</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172747"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172747"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679172746"><span class="annot"><span class="annottext">[Tree a]
</span><a href="#local-6989586621679172746"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172747"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([a] -&gt; [a]) -&gt; ([a] -&gt; [a]) -&gt; [a] -&gt; [a]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree a] -&gt; [a] -&gt; [a]
forall a. Forest a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#preorderF%27"><span class="hs-identifier hs-var">preorderF'</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree a]
</span><a href="#local-6989586621679172746"><span class="hs-identifier hs-var">ts</span></a></span><span>
</span><span id="line-585"></span><span>
</span><span id="line-586"></span><span id="local-6989586621679173360"><span class="annot"><a href="Data.Graph.html#preorderF%27"><span class="hs-identifier hs-type">preorderF'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173360"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173360"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173360"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-587"></span><span id="preorderF%27"><span class="annot"><span class="annottext">preorderF' :: forall a. Forest a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#preorderF%27"><span class="hs-identifier hs-var hs-var">preorderF'</span></a></span></span><span> </span><span id="local-6989586621679172742"><span class="annot"><span class="annottext">Forest a
</span><a href="#local-6989586621679172742"><span class="hs-identifier hs-var">ts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(([a] -&gt; [a]) -&gt; ([a] -&gt; [a]) -&gt; [a] -&gt; [a])
-&gt; ([a] -&gt; [a]) -&gt; [[a] -&gt; [a]] -&gt; [a] -&gt; [a]
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">([a] -&gt; [a]) -&gt; ([a] -&gt; [a]) -&gt; [a] -&gt; [a]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">(.)</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. a -&gt; a
</span><a href="../../base/src/GHC.Base.html#id"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">([[a] -&gt; [a]] -&gt; [a] -&gt; [a]) -&gt; [[a] -&gt; [a]] -&gt; [a] -&gt; [a]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(Tree a -&gt; [a] -&gt; [a]) -&gt; Forest a -&gt; [[a] -&gt; [a]]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Tree a -&gt; [a] -&gt; [a]
forall a. Tree a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#preorder%27"><span class="hs-identifier hs-var">preorder'</span></a></span><span> </span><span class="annot"><span class="annottext">Forest a
</span><a href="#local-6989586621679172742"><span class="hs-identifier hs-var">ts</span></a></span><span>
</span><span id="line-588"></span><span>
</span><span id="line-589"></span><span id="local-6989586621679173356"><span class="annot"><a href="Data.Graph.html#preorderF"><span class="hs-identifier hs-type">preorderF</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679173356"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679173356"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-590"></span><span id="preorderF"><span class="annot"><span class="annottext">preorderF :: forall a. Forest a -&gt; [a]
</span><a href="Data.Graph.html#preorderF"><span class="hs-identifier hs-var hs-var">preorderF</span></a></span></span><span> </span><span id="local-6989586621679172739"><span class="annot"><span class="annottext">Forest a
</span><a href="#local-6989586621679172739"><span class="hs-identifier hs-var">ts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Forest a -&gt; [a] -&gt; [a]
forall a. Forest a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#preorderF%27"><span class="hs-identifier hs-var">preorderF'</span></a></span><span> </span><span class="annot"><span class="annottext">Forest a
</span><a href="#local-6989586621679172739"><span class="hs-identifier hs-var">ts</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-591"></span><span>
</span><span id="line-592"></span><span class="annot"><a href="Data.Graph.html#tabulate"><span class="hs-identifier hs-type">tabulate</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Bounds"><span class="hs-identifier hs-type">Bounds</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Base.html#UArray"><span class="hs-identifier hs-type">UArray</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-593"></span><span id="tabulate"><span class="annot"><span class="annottext">tabulate :: Edge -&gt; [Int] -&gt; UArray Int Int
</span><a href="Data.Graph.html#tabulate"><span class="hs-identifier hs-var hs-var">tabulate</span></a></span></span><span> </span><span id="local-6989586621679172737"><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172737"><span class="hs-identifier hs-var">bnds</span></a></span></span><span> </span><span id="local-6989586621679172736"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172736"><span class="hs-identifier hs-var">vs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [Edge] -&gt; UArray Int Int
forall (a :: * -&gt; * -&gt; *) e i.
(IArray a e, Ix i) =&gt;
(i, i) -&gt; [(i, e)] -&gt; a i e
</span><a href="../../array/src/Data.Array.Base.html#array"><span class="hs-identifier hs-var">UA.array</span></a></span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172737"><span class="hs-identifier hs-var">bnds</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Int -&gt; Int -&gt; Edge) -&gt; [Int] -&gt; [Int] -&gt; [Edge]
forall a b c. (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]
</span><a href="../../base/src/GHC.List.html#zipWith"><span class="hs-identifier hs-var">zipWith</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Int -&gt; Int -&gt; Edge) -&gt; Int -&gt; Int -&gt; Edge
forall a b c. (a -&gt; b -&gt; c) -&gt; b -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#flip"><span class="hs-identifier hs-var">flip</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">,</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-glyph">..</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172736"><span class="hs-identifier hs-var">vs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-594"></span><span class="hs-comment">-- Why zipWith (flip (,)) instead of just using zip with the</span><span>
</span><span id="line-595"></span><span class="hs-comment">-- arguments in the other order? We want the [1..] to fuse</span><span>
</span><span id="line-596"></span><span class="hs-comment">-- away, and these days that only happens when it's the first</span><span>
</span><span id="line-597"></span><span class="hs-comment">-- list argument.</span><span>
</span><span id="line-598"></span><span>
</span><span id="line-599"></span><span class="annot"><a href="Data.Graph.html#preArr"><span class="hs-identifier hs-type">preArr</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Bounds"><span class="hs-identifier hs-type">Bounds</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Base.html#UArray"><span class="hs-identifier hs-type">UArray</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-600"></span><span id="preArr"><span class="annot"><span class="annottext">preArr :: Edge -&gt; [Tree Int] -&gt; UArray Int Int
</span><a href="Data.Graph.html#preArr"><span class="hs-identifier hs-var hs-var">preArr</span></a></span></span><span> </span><span id="local-6989586621679172733"><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172733"><span class="hs-identifier hs-var">bnds</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [Int] -&gt; UArray Int Int
</span><a href="Data.Graph.html#tabulate"><span class="hs-identifier hs-var">tabulate</span></a></span><span> </span><span class="annot"><span class="annottext">Edge
</span><a href="#local-6989586621679172733"><span class="hs-identifier hs-var">bnds</span></a></span><span> </span><span class="annot"><span class="annottext">([Int] -&gt; UArray Int Int)
-&gt; ([Tree Int] -&gt; [Int]) -&gt; [Tree Int] -&gt; UArray Int Int
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree Int] -&gt; [Int]
forall a. Forest a -&gt; [a]
</span><a href="Data.Graph.html#preorderF"><span class="hs-identifier hs-var">preorderF</span></a></span><span>
</span><span id="line-601"></span><span>
</span><span id="line-602"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-603"></span><span class="hs-comment">-- Algorithm 2: topological sorting</span><span>
</span><span id="line-604"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-605"></span><span>
</span><span id="line-606"></span><span id="local-6989586621679172732"><span class="annot"><a href="Data.Graph.html#postorder"><span class="hs-identifier hs-type">postorder</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679172732"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679172732"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679172732"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-607"></span><span id="postorder"><span class="annot"><span class="annottext">postorder :: forall a. Tree a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#postorder"><span class="hs-identifier hs-var hs-var">postorder</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172730"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172730"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679172729"><span class="annot"><span class="annottext">[Tree a]
</span><a href="#local-6989586621679172729"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Tree a] -&gt; [a] -&gt; [a]
forall a. Forest a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#postorderF"><span class="hs-identifier hs-var">postorderF</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree a]
</span><a href="#local-6989586621679172729"><span class="hs-identifier hs-var">ts</span></a></span><span> </span><span class="annot"><span class="annottext">([a] -&gt; [a]) -&gt; ([a] -&gt; [a]) -&gt; [a] -&gt; [a]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679172730"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="hs-special">)</span><span>
</span><span id="line-608"></span><span>
</span><span id="line-609"></span><span id="local-6989586621679172727"><span class="annot"><a href="Data.Graph.html#postorderF"><span class="hs-identifier hs-type">postorderF</span></a></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679172727"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679172727"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679172727"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-610"></span><span id="postorderF"><span class="annot"><span class="annottext">postorderF :: forall a. Forest a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#postorderF"><span class="hs-identifier hs-var hs-var">postorderF</span></a></span></span><span> </span><span id="local-6989586621679172725"><span class="annot"><span class="annottext">Forest a
</span><a href="#local-6989586621679172725"><span class="hs-identifier hs-var">ts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(([a] -&gt; [a]) -&gt; ([a] -&gt; [a]) -&gt; [a] -&gt; [a])
-&gt; ([a] -&gt; [a]) -&gt; [[a] -&gt; [a]] -&gt; [a] -&gt; [a]
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">([a] -&gt; [a]) -&gt; ([a] -&gt; [a]) -&gt; [a] -&gt; [a]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">(.)</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. a -&gt; a
</span><a href="../../base/src/GHC.Base.html#id"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">([[a] -&gt; [a]] -&gt; [a] -&gt; [a]) -&gt; [[a] -&gt; [a]] -&gt; [a] -&gt; [a]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(Tree a -&gt; [a] -&gt; [a]) -&gt; Forest a -&gt; [[a] -&gt; [a]]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Tree a -&gt; [a] -&gt; [a]
forall a. Tree a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#postorder"><span class="hs-identifier hs-var">postorder</span></a></span><span> </span><span class="annot"><span class="annottext">Forest a
</span><a href="#local-6989586621679172725"><span class="hs-identifier hs-var">ts</span></a></span><span>
</span><span id="line-611"></span><span>
</span><span id="line-612"></span><span class="annot"><a href="Data.Graph.html#postOrd"><span class="hs-identifier hs-type">postOrd</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-613"></span><span id="postOrd"><span class="annot"><span class="annottext">postOrd :: Graph -&gt; [Int]
</span><a href="Data.Graph.html#postOrd"><span class="hs-identifier hs-var hs-var">postOrd</span></a></span></span><span> </span><span id="local-6989586621679172723"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172723"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Tree Int] -&gt; [Int] -&gt; [Int]
forall a. Forest a -&gt; [a] -&gt; [a]
</span><a href="Data.Graph.html#postorderF"><span class="hs-identifier hs-var">postorderF</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; [Tree Int]
</span><a href="Data.Graph.html#dff"><span class="hs-identifier hs-var">dff</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172723"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-614"></span><span>
</span><span id="line-615"></span><span class="hs-comment">-- | A topological sort of the graph.</span><span>
</span><span id="line-616"></span><span class="hs-comment">-- The order is partially specified by the condition that a vertex /i/</span><span>
</span><span id="line-617"></span><span class="hs-comment">-- precedes /j/ whenever /j/ is reachable from /i/ but not vice versa.</span><span>
</span><span id="line-618"></span><span class="annot"><a href="Data.Graph.html#topSort"><span class="hs-identifier hs-type">topSort</span></a></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-619"></span><span id="topSort"><span class="annot"><span class="annottext">topSort :: Graph -&gt; [Int]
</span><a href="Data.Graph.html#topSort"><span class="hs-identifier hs-var hs-var">topSort</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; [Int]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">([Int] -&gt; [Int]) -&gt; (Graph -&gt; [Int]) -&gt; Graph -&gt; [Int]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Int]
</span><a href="Data.Graph.html#postOrd"><span class="hs-identifier hs-var">postOrd</span></a></span><span>
</span><span id="line-620"></span><span>
</span><span id="line-621"></span><span class="hs-comment">-- | Reverse ordering of `topSort`.</span><span>
</span><span id="line-622"></span><span class="hs-comment">--</span><span>
</span><span id="line-623"></span><span class="hs-comment">-- @since 0.6.4</span><span>
</span><span id="line-624"></span><span class="annot"><a href="Data.Graph.html#reverseTopSort"><span class="hs-identifier hs-type">reverseTopSort</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-625"></span><span id="reverseTopSort"><span class="annot"><span class="annottext">reverseTopSort :: Graph -&gt; [Int]
</span><a href="Data.Graph.html#reverseTopSort"><span class="hs-identifier hs-var hs-var">reverseTopSort</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Int]
</span><a href="Data.Graph.html#postOrd"><span class="hs-identifier hs-var">postOrd</span></a></span><span>
</span><span id="line-626"></span><span>
</span><span id="line-627"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-628"></span><span class="hs-comment">-- Algorithm 3: connected components</span><span>
</span><span id="line-629"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-630"></span><span>
</span><span id="line-631"></span><span class="hs-comment">-- | The connected components of a graph.</span><span>
</span><span id="line-632"></span><span class="hs-comment">-- Two vertices are connected if there is a path between them, traversing</span><span>
</span><span id="line-633"></span><span class="hs-comment">-- edges in either direction.</span><span>
</span><span id="line-634"></span><span class="annot"><a href="Data.Graph.html#components"><span class="hs-identifier hs-type">components</span></a></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span>
</span><span id="line-635"></span><span id="components"><span class="annot"><span class="annottext">components :: Graph -&gt; [Tree Int]
</span><a href="Data.Graph.html#components"><span class="hs-identifier hs-var hs-var">components</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Tree Int]
</span><a href="Data.Graph.html#dff"><span class="hs-identifier hs-var">dff</span></a></span><span> </span><span class="annot"><span class="annottext">(Graph -&gt; [Tree Int]) -&gt; (Graph -&gt; Graph) -&gt; Graph -&gt; [Tree Int]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Graph -&gt; Graph
</span><a href="Data.Graph.html#undirected"><span class="hs-identifier hs-var">undirected</span></a></span><span>
</span><span id="line-636"></span><span>
</span><span id="line-637"></span><span class="annot"><a href="Data.Graph.html#undirected"><span class="hs-identifier hs-type">undirected</span></a></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span>
</span><span id="line-638"></span><span id="undirected"><span class="annot"><span class="annottext">undirected :: Graph -&gt; Graph
</span><a href="Data.Graph.html#undirected"><span class="hs-identifier hs-var hs-var">undirected</span></a></span></span><span> </span><span id="local-6989586621679172720"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172720"><span class="hs-identifier hs-var">g</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [Edge] -&gt; Graph
</span><a href="Data.Graph.html#buildG"><span class="hs-identifier hs-var">buildG</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Edge
forall i e. Array i e -&gt; (i, i)
</span><a href="../../base/src/GHC.Arr.html#bounds"><span class="hs-identifier hs-var">bounds</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172720"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; [Edge]
</span><a href="Data.Graph.html#edges"><span class="hs-identifier hs-var">edges</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172720"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="annot"><span class="annottext">[Edge] -&gt; [Edge] -&gt; [Edge]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Edge]
</span><a href="Data.Graph.html#reverseE"><span class="hs-identifier hs-var">reverseE</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172720"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-639"></span><span>
</span><span id="line-640"></span><span class="hs-comment">-- Algorithm 4: strongly connected components</span><span>
</span><span id="line-641"></span><span>
</span><span id="line-642"></span><span class="hs-comment">-- | The strongly connected components of a graph, in reverse topological order.</span><span>
</span><span id="line-643"></span><span class="hs-comment">--</span><span>
</span><span id="line-644"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-645"></span><span class="hs-comment">--</span><span>
</span><span id="line-646"></span><span class="hs-comment">-- &gt; scc (buildG (0,3) [(3,1),(1,2),(2,0),(0,1)])</span><span>
</span><span id="line-647"></span><span class="hs-comment">-- &gt;   == [Node {rootLabel = 0, subForest = [Node {rootLabel = 1, subForest = [Node {rootLabel = 2, subForest = []}]}]}</span><span>
</span><span id="line-648"></span><span class="hs-comment">-- &gt;      ,Node {rootLabel = 3, subForest = []}]</span><span>
</span><span id="line-649"></span><span>
</span><span id="line-650"></span><span class="annot"><a href="Data.Graph.html#scc"><span class="hs-identifier hs-type">scc</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span>
</span><span id="line-651"></span><span id="scc"><span class="annot"><span class="annottext">scc :: Graph -&gt; [Tree Int]
</span><a href="Data.Graph.html#scc"><span class="hs-identifier hs-var hs-var">scc</span></a></span></span><span> </span><span id="local-6989586621679172719"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172719"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Int] -&gt; [Tree Int]
</span><a href="Data.Graph.html#dfs"><span class="hs-identifier hs-var">dfs</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172719"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Int] -&gt; [Int]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; [Int]
</span><a href="Data.Graph.html#postOrd"><span class="hs-identifier hs-var">postOrd</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Graph
</span><a href="Data.Graph.html#transposeG"><span class="hs-identifier hs-var">transposeG</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172719"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-652"></span><span>
</span><span id="line-653"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-654"></span><span class="hs-comment">-- Algorithm 5: Classifying edges</span><span>
</span><span id="line-655"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-656"></span><span>
</span><span id="line-657"></span><span class="hs-comment">{-
XXX unused code

tree              :: Bounds -&gt; Forest Vertex -&gt; Graph
tree bnds ts       = buildG bnds (concat (map flat ts))
 where flat (Node v ts') = [ (v, w) | Node w _us &lt;- ts' ]
                        ++ concat (map flat ts')

back              :: Graph -&gt; Table Int -&gt; Graph
back g post        = mapT select g
 where select v ws = [ w | w &lt;- ws, post!v &lt; post!w ]

cross             :: Graph -&gt; Table Int -&gt; Table Int -&gt; Graph
cross g pre post   = mapT select g
 where select v ws = [ w | w &lt;- ws, post!v &gt; post!w, pre!v &gt; pre!w ]

forward           :: Graph -&gt; Graph -&gt; Table Int -&gt; Graph
forward g tree' pre = mapT select g
 where select v ws = [ w | w &lt;- ws, pre!v &lt; pre!w ] \\ tree' ! v

mapT    :: (Vertex -&gt; a -&gt; b) -&gt; Array Vertex a -&gt; Array Vertex b
mapT f t = array (bounds t) [ (,) v (f v (t!v)) | v &lt;- indices t ]
-}</span><span>
</span><span id="line-680"></span><span>
</span><span id="line-681"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-682"></span><span class="hs-comment">-- Algorithm 6: Finding reachable vertices</span><span>
</span><span id="line-683"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-684"></span><span>
</span><span id="line-685"></span><span class="hs-comment">-- | Returns the list of vertices reachable from a given vertex.</span><span>
</span><span id="line-686"></span><span class="hs-comment">--</span><span>
</span><span id="line-687"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-688"></span><span class="hs-comment">--</span><span>
</span><span id="line-689"></span><span class="hs-comment">-- &gt; reachable (buildG (0,0) []) 0 == [0]</span><span>
</span><span id="line-690"></span><span class="hs-comment">--</span><span>
</span><span id="line-691"></span><span class="hs-comment">-- &gt; reachable (buildG (0,2) [(0,1), (1,2)]) 0 == [0,1,2]</span><span>
</span><span id="line-692"></span><span class="annot"><a href="Data.Graph.html#reachable"><span class="hs-identifier hs-type">reachable</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-693"></span><span id="reachable"><span class="annot"><span class="annottext">reachable :: Graph -&gt; Int -&gt; [Int]
</span><a href="Data.Graph.html#reachable"><span class="hs-identifier hs-var hs-var">reachable</span></a></span></span><span> </span><span id="local-6989586621679172718"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172718"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span id="local-6989586621679172717"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172717"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Tree Int] -&gt; [Int]
forall a. Forest a -&gt; [a]
</span><a href="Data.Graph.html#preorderF"><span class="hs-identifier hs-var">preorderF</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; [Int] -&gt; [Tree Int]
</span><a href="Data.Graph.html#dfs"><span class="hs-identifier hs-var">dfs</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172718"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172717"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-694"></span><span>
</span><span id="line-695"></span><span class="hs-comment">-- | Returns @True@ if the second vertex reachable from the first.</span><span>
</span><span id="line-696"></span><span class="hs-comment">--</span><span>
</span><span id="line-697"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-698"></span><span class="hs-comment">--</span><span>
</span><span id="line-699"></span><span class="hs-comment">-- &gt; path (buildG (0,0) []) 0 0 == True</span><span>
</span><span id="line-700"></span><span class="hs-comment">--</span><span>
</span><span id="line-701"></span><span class="hs-comment">-- &gt; path (buildG (0,2) [(0,1), (1,2)]) 0 2 == True</span><span>
</span><span id="line-702"></span><span class="hs-comment">--</span><span>
</span><span id="line-703"></span><span class="hs-comment">-- &gt; path (buildG (0,2) [(0,1), (1,2)]) 2 0 == False</span><span>
</span><span id="line-704"></span><span class="annot"><a href="Data.Graph.html#path"><span class="hs-identifier hs-type">path</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-705"></span><span id="path"><span class="annot"><span class="annottext">path :: Graph -&gt; Int -&gt; Int -&gt; Bool
</span><a href="Data.Graph.html#path"><span class="hs-identifier hs-var hs-var">path</span></a></span></span><span> </span><span id="local-6989586621679172716"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172716"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span id="local-6989586621679172715"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172715"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621679172714"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172714"><span class="hs-identifier hs-var">w</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172714"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; [Int] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Int -&gt; [Int]
</span><a href="Data.Graph.html#reachable"><span class="hs-identifier hs-var">reachable</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172716"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172715"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-706"></span><span>
</span><span id="line-707"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-708"></span><span class="hs-comment">-- Algorithm 7: Biconnected components</span><span>
</span><span id="line-709"></span><span class="hs-comment">------------------------------------------------------------</span><span>
</span><span id="line-710"></span><span>
</span><span id="line-711"></span><span class="hs-comment">-- | The biconnected components of a graph.</span><span>
</span><span id="line-712"></span><span class="hs-comment">-- An undirected graph is biconnected if the deletion of any vertex</span><span>
</span><span id="line-713"></span><span class="hs-comment">-- leaves it connected.</span><span>
</span><span id="line-714"></span><span class="annot"><a href="Data.Graph.html#bcc"><span class="hs-identifier hs-type">bcc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-715"></span><span id="bcc"><span class="annot"><span class="annottext">bcc :: Graph -&gt; Forest [Int]
</span><a href="Data.Graph.html#bcc"><span class="hs-identifier hs-var hs-var">bcc</span></a></span></span><span> </span><span id="local-6989586621679172713"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172713"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Forest [Int]] -&gt; Forest [Int]
forall (t :: * -&gt; *) a. Foldable t =&gt; t [a] -&gt; [a]
</span><a href="../../base/src/Data.Foldable.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="annot"><span class="annottext">([Forest [Int]] -&gt; Forest [Int])
-&gt; ([Tree Int] -&gt; [Forest [Int]]) -&gt; [Tree Int] -&gt; Forest [Int]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Tree (Int, Int, Int) -&gt; Forest [Int])
-&gt; [Tree (Int, Int, Int)] -&gt; [Forest [Int]]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Tree (Int, Int, Int) -&gt; Forest [Int]
</span><a href="Data.Graph.html#bicomps"><span class="hs-identifier hs-var">bicomps</span></a></span><span> </span><span class="annot"><span class="annottext">([Tree (Int, Int, Int)] -&gt; [Forest [Int]])
-&gt; ([Tree Int] -&gt; [Tree (Int, Int, Int)])
-&gt; [Tree Int]
-&gt; [Forest [Int]]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Tree Int -&gt; Tree (Int, Int, Int))
-&gt; [Tree Int] -&gt; [Tree (Int, Int, Int)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; UArray Int Int -&gt; Tree Int -&gt; Tree (Int, Int, Int)
</span><a href="Data.Graph.html#do_label"><span class="hs-identifier hs-var">do_label</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172713"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="annot"><span class="annottext">UArray Int Int
</span><a href="#local-6989586621679172709"><span class="hs-identifier hs-var">dnum</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172708"><span class="hs-identifier hs-var">forest</span></a></span><span>
</span><span id="line-716"></span><span> </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679172708"><span class="annot"><span class="annottext">forest :: [Tree Int]
</span><a href="#local-6989586621679172708"><span class="hs-identifier hs-var hs-var">forest</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Graph -&gt; [Tree Int]
</span><a href="Data.Graph.html#dff"><span class="hs-identifier hs-var">dff</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172713"><span class="hs-identifier hs-var">g</span></a></span><span>
</span><span id="line-717"></span><span>       </span><span id="local-6989586621679172709"><span class="annot"><span class="annottext">dnum :: UArray Int Int
</span><a href="#local-6989586621679172709"><span class="hs-identifier hs-var hs-var">dnum</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Edge -&gt; [Tree Int] -&gt; UArray Int Int
</span><a href="Data.Graph.html#preArr"><span class="hs-identifier hs-var">preArr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; Edge
forall i e. Array i e -&gt; (i, i)
</span><a href="../../base/src/GHC.Arr.html#bounds"><span class="hs-identifier hs-var">bounds</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172713"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172708"><span class="hs-identifier hs-var">forest</span></a></span><span>
</span><span id="line-718"></span><span>
</span><span id="line-719"></span><span class="annot"><a href="Data.Graph.html#do_label"><span class="hs-identifier hs-type">do_label</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Graph.html#Graph"><span class="hs-identifier hs-type">Graph</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../array/src/Data.Array.Base.html#UArray"><span class="hs-identifier hs-type">UArray</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">)</span><span>
</span><span id="line-720"></span><span id="do_label"><span class="annot"><span class="annottext">do_label :: Graph -&gt; UArray Int Int -&gt; Tree Int -&gt; Tree (Int, Int, Int)
</span><a href="Data.Graph.html#do_label"><span class="hs-identifier hs-var hs-var">do_label</span></a></span></span><span> </span><span id="local-6989586621679172707"><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172707"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span id="local-6989586621679172706"><span class="annot"><span class="annottext">UArray Int Int
</span><a href="#local-6989586621679172706"><span class="hs-identifier hs-var">dnum</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172705"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172705"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621679172704"><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172704"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Int, Int, Int) -&gt; [Tree (Int, Int, Int)] -&gt; Tree (Int, Int, Int)
forall a. a -&gt; [Tree a] -&gt; Tree a
</span><a href="Data.Tree.html#Node"><span class="hs-identifier hs-var">Node</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172705"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">UArray Int Int
</span><a href="#local-6989586621679172706"><span class="hs-identifier hs-var">dnum</span></a></span><span> </span><span class="annot"><span class="annottext">UArray Int Int -&gt; Int -&gt; Int
forall (a :: * -&gt; * -&gt; *) e i.
(IArray a e, Ix i) =&gt;
a i e -&gt; i -&gt; e
</span><a href="../../array/src/Data.Array.Base.html#%21"><span class="hs-operator hs-var">UA.!</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172705"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172702"><span class="hs-identifier hs-var">lv</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Tree (Int, Int, Int)]
</span><a href="#local-6989586621679172701"><span class="hs-identifier hs-var">us</span></a></span><span>
</span><span id="line-721"></span><span> </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679172701"><span class="annot"><span class="annottext">us :: [Tree (Int, Int, Int)]
</span><a href="#local-6989586621679172701"><span class="hs-identifier hs-var hs-var">us</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Tree Int -&gt; Tree (Int, Int, Int))
-&gt; [Tree Int] -&gt; [Tree (Int, Int, Int)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Graph -&gt; UArray Int Int -&gt; Tree Int -&gt; Tree (Int, Int, Int)
</span><a href="Data.Graph.html#do_label"><span class="hs-identifier hs-var">do_label</span></a></span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172707"><span class="hs-identifier hs-var">g</span></a></span><span> </span><span class="annot"><span class="annottext">UArray Int Int
</span><a href="#local-6989586621679172706"><span class="hs-identifier hs-var">dnum</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Tree Int]
</span><a href="#local-6989586621679172704"><span class="hs-identifier hs-var">ts</span></a></span><span>
</span><span id="line-722"></span><span>       </span><span id="local-6989586621679172702"><span class="annot"><span class="annottext">lv :: Int
</span><a href="#local-6989586621679172702"><span class="hs-identifier hs-var hs-var">lv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Int
forall (t :: * -&gt; *) a. (Foldable t, Ord a) =&gt; t a -&gt; a
</span><a href="../../base/src/Data.Foldable.html#minimum"><span class="hs-identifier hs-var">minimum</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><span class="annottext">UArray Int Int
</span><a href="#local-6989586621679172706"><span class="hs-identifier hs-var">dnum</span></a></span><span> </span><span class="annot"><span class="annottext">UArray Int Int -&gt; Int -&gt; Int
forall (a :: * -&gt; * -&gt; *) e i.
(IArray a e, Ix i) =&gt;
a i e -&gt; i -&gt; e
</span><a href="../../array/src/Data.Array.Base.html#%21"><span class="hs-operator hs-var">UA.!</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172705"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; [Int] -&gt; [Int]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">UArray Int Int
</span><a href="#local-6989586621679172706"><span class="hs-identifier hs-var">dnum</span></a></span><span> </span><span class="annot"><span class="annottext">UArray Int Int -&gt; Int -&gt; Int
forall (a :: * -&gt; * -&gt; *) e i.
(IArray a e, Ix i) =&gt;
a i e -&gt; i -&gt; e
</span><a href="../../array/src/Data.Array.Base.html#%21"><span class="hs-operator hs-var">UA.!</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172692"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621679172692"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172692"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Graph
</span><a href="#local-6989586621679172707"><span class="hs-identifier hs-var">g</span></a></span><span class="annot"><span class="annottext">Graph -&gt; Int -&gt; [Int]
forall i e. Ix i =&gt; Array i e -&gt; i -&gt; e
</span><a href="../../base/src/GHC.Arr.html#%21"><span class="hs-operator hs-var">!</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172705"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-723"></span><span>                     </span><span class="annot"><span class="annottext">[Int] -&gt; [Int] -&gt; [Int]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172691"><span class="hs-identifier hs-var">lu</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621679172691"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172691"><span class="hs-identifier hs-var">lu</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Tree (Int, Int, Int)]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Tree (Int, Int, Int)]
</span><a href="#local-6989586621679172701"><span class="hs-identifier hs-var">us</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-724"></span><span>
</span><span id="line-725"></span><span class="annot"><a href="Data.Graph.html#bicomps"><span class="hs-identifier hs-type">bicomps</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Tree.html#Forest"><span class="hs-identifier hs-type">Forest</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-726"></span><span id="bicomps"><span class="annot"><span class="annottext">bicomps :: Tree (Int, Int, Int) -&gt; Forest [Int]
</span><a href="Data.Graph.html#bicomps"><span class="hs-identifier hs-var hs-var">bicomps</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172690"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172690"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679172689"><span class="annot"><span class="annottext">[Tree (Int, Int, Int)]
</span><a href="#local-6989586621679172689"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-727"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Forest [Int] -&gt; Tree [Int]
forall a. a -&gt; [Tree a] -&gt; Tree a
</span><a href="Data.Tree.html#Node"><span class="hs-identifier hs-var">Node</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172690"><span class="hs-identifier hs-var">v</span></a></span><span class="annot"><span class="annottext">Int -&gt; [Int] -&gt; [Int]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172688"><span class="hs-identifier hs-var">vs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Forest [Int]
</span><a href="#local-6989586621679172687"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172688"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172688"><span class="hs-identifier hs-var">vs</span></a></span></span><span> </span><span id="local-6989586621679172687"><span class="annot"><span class="annottext">Forest [Int]
</span><a href="#local-6989586621679172687"><span class="hs-identifier hs-var">us</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Tree (Int, Int, Int) -&gt; (Int, Tree [Int]))
-&gt; [Tree (Int, Int, Int)] -&gt; [(Int, Tree [Int])]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Tree (Int, Int, Int) -&gt; (Int, Tree [Int])
</span><a href="Data.Graph.html#collect"><span class="hs-identifier hs-var">collect</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree (Int, Int, Int)]
</span><a href="#local-6989586621679172689"><span class="hs-identifier hs-var">ts</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-728"></span><span>
</span><span id="line-729"></span><span class="annot"><a href="Data.Graph.html#collect"><span class="hs-identifier hs-type">collect</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Tree.html#Tree"><span class="hs-identifier hs-type">Tree</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Data.Graph.html#Vertex"><span class="hs-identifier hs-type">Vertex</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-730"></span><span id="collect"><span class="annot"><span class="annottext">collect :: Tree (Int, Int, Int) -&gt; (Int, Tree [Int])
</span><a href="Data.Graph.html#collect"><span class="hs-identifier hs-var hs-var">collect</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172685"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172685"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679172684"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172684"><span class="hs-identifier hs-var">dv</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679172683"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172683"><span class="hs-identifier hs-var">lv</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679172682"><span class="annot"><span class="annottext">[Tree (Int, Int, Int)]
</span><a href="#local-6989586621679172682"><span class="hs-identifier hs-var">ts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172683"><span class="hs-identifier hs-var">lv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Int] -&gt; Forest [Int] -&gt; Tree [Int]
forall a. a -&gt; [Tree a] -&gt; Tree a
</span><a href="Data.Tree.html#Node"><span class="hs-identifier hs-var">Node</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172685"><span class="hs-identifier hs-var">v</span></a></span><span class="annot"><span class="annottext">Int -&gt; [Int] -&gt; [Int]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172681"><span class="hs-identifier hs-var">vs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Forest [Int]
</span><a href="#local-6989586621679172680"><span class="hs-identifier hs-var">cs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-731"></span><span> </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679172679"><span class="annot"><span class="annottext">collected :: [(Int, Tree [Int])]
</span><a href="#local-6989586621679172679"><span class="hs-identifier hs-var hs-var">collected</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Tree (Int, Int, Int) -&gt; (Int, Tree [Int]))
-&gt; [Tree (Int, Int, Int)] -&gt; [(Int, Tree [Int])]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">Tree (Int, Int, Int) -&gt; (Int, Tree [Int])
</span><a href="Data.Graph.html#collect"><span class="hs-identifier hs-var">collect</span></a></span><span> </span><span class="annot"><span class="annottext">[Tree (Int, Int, Int)]
</span><a href="#local-6989586621679172682"><span class="hs-identifier hs-var">ts</span></a></span><span>
</span><span id="line-732"></span><span>       </span><span id="local-6989586621679172681"><span class="annot"><span class="annottext">vs :: [Int]
</span><a href="#local-6989586621679172681"><span class="hs-identifier hs-var hs-var">vs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[[Int]] -&gt; [Int]
forall (t :: * -&gt; *) a. Foldable t =&gt; t [a] -&gt; [a]
</span><a href="../../base/src/Data.Foldable.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172676"><span class="hs-identifier hs-var">ws</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172675"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172675"><span class="hs-identifier hs-var">lw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172676"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172676"><span class="hs-identifier hs-var">ws</span></a></span></span><span> </span><span class="annot"><span class="annottext">Forest [Int]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Int, Tree [Int])]
</span><a href="#local-6989586621679172679"><span class="hs-identifier hs-var">collected</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172675"><span class="hs-identifier hs-var">lw</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172684"><span class="hs-identifier hs-var">dv</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-733"></span><span>       </span><span id="local-6989586621679172680"><span class="annot"><span class="annottext">cs :: Forest [Int]
</span><a href="#local-6989586621679172680"><span class="hs-identifier hs-var hs-var">cs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Forest [Int]] -&gt; Forest [Int]
forall (t :: * -&gt; *) a. Foldable t =&gt; t [a] -&gt; [a]
</span><a href="../../base/src/Data.Foldable.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172671"><span class="hs-identifier hs-var">lw</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172684"><span class="hs-identifier hs-var">dv</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Forest [Int]
</span><a href="#local-6989586621679172670"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">[Int] -&gt; Forest [Int] -&gt; Tree [Int]
forall a. a -&gt; [Tree a] -&gt; Tree a
</span><a href="Data.Tree.html#Node"><span class="hs-identifier hs-var">Node</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172685"><span class="hs-identifier hs-var">v</span></a></span><span class="annot"><span class="annottext">Int -&gt; [Int] -&gt; [Int]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172669"><span class="hs-identifier hs-var">ws</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Forest [Int]
</span><a href="#local-6989586621679172670"><span class="hs-identifier hs-var">us</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-734"></span><span>                        </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679172671"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679172671"><span class="hs-identifier hs-var">lw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Tree.html#Node"><span class="hs-identifier hs-type">Node</span></a></span><span> </span><span id="local-6989586621679172669"><span class="annot"><span class="annottext">[Int]
</span><a href="#local-6989586621679172669"><span class="hs-identifier hs-var">ws</span></a></span></span><span> </span><span id="local-6989586621679172670"><span class="annot"><span class="annottext">Forest [Int]
</span><a href="#local-6989586621679172670"><span class="hs-identifier hs-var">us</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Int, Tree [Int])]
</span><a href="#local-6989586621679172679"><span class="hs-identifier hs-var">collected</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-735"></span></pre></body></html>